示例#1
1
 public static int Step(Sqlite3.Vdbe statement)
 {
     if(statement == null)
         return Sqlite3.SQLITE_OK;
     else
         return Sqlite3.sqlite3_step(statement);
 }
示例#2
0
        private Statement(Sqlite3.sqlite3 db, sqlite3_stmt stmt, string operation, string tail)
        {
            this.uniqueid = Guid.NewGuid();

            this.db = db;
            this.sql = operation;

            this.st = stmt;
            this.Tail = tail;
        }
示例#3
0
    private static DBAdapter getDBByHandle(Sqlite3.sqlite3 db)
    {
        Hashtable<String, DBAdapter>.Enumerator hashEnum = m_mapDBPartitions.GetEnumerator();
		while( hashEnum.MoveNext() )
		{
            if(hashEnum.Current.Value.m_dbStorage == db)
			    return hashEnum.Current.Value;
		}

        return getDBPartitions().get(USER_PARTITION_NAME());
    }
示例#4
0
 internal SqliteDataReader(SqliteCommand cmd, Sqlite3.Vdbe pVm, int version)
 {
     command = cmd;
     rows = new ArrayList ();
     column_names_sens = new Hashtable ();
     column_names_insens = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
     closed = false;
     current_row = -1;
     reading = true;
     ReadpVm (pVm, version, cmd);
     ReadingDone ();
 }
示例#5
0
		internal SqliteDataReader (SqliteCommand cmd, Sqlite3.Vdbe pVm, int version)
		{
			command = cmd;
            rows = new List<object[]>();
            column_names_sens = new Dictionary<String, Object>();
            column_names_insens = new Dictionary<String, Object>( StringComparer.InvariantCultureIgnoreCase );
			closed = false;
			current_row = -1;
			reading = true;
			ReadpVm (pVm, version, cmd);
			ReadingDone ();
		}
示例#6
0
    public static void SyncBlob_UpdateCallback(Sqlite3.sqlite3_context dbContext, int nArgs, Sqlite3.Mem[] Args)
    {
        if (nArgs < 3)
            return;

        DBAttrManager attrMgr = getDBByHandle(Sqlite3.sqlite3_context_db_handle(dbContext)).getAttrMgr();

        String szAttrName = Sqlite3.sqlite3_value_text(Args[2]);
        int nSrcID = Sqlite3.sqlite3_value_int(Args[1]);
        if (attrMgr.isBlobAttr(nSrcID, szAttrName))
        {
            String strFilePath = RHODESAPP().resolveDBFilesPath(Sqlite3.sqlite3_value_text(Args[0]));
            CRhoFile.deleteFile(strFilePath);
        }
    }
		internal SqliteDataReader (SqliteCommand cmd, Sqlite3.Vdbe pVm, int version)
		{
			command = cmd;
			rows = new ArrayList ();
			column_names_sens = new Hashtable ();
#if NET_2_0
			column_names_insens = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
#else
			column_names_insens = new Hashtable (CaseInsensitiveHashCodeProvider.DefaultInvariant,
							     CaseInsensitiveComparer.DefaultInvariant);
#endif
			closed = false;
			current_row = -1;
			reading = true;
			ReadpVm (pVm, version, cmd);
			ReadingDone ();
		}
示例#8
0
		// Executes a statement and returns whether there is more data available.
		internal bool ExecuteStatement( Sqlite3.Vdbe pStmt, out int cols, out IntPtr pazValue, out IntPtr pazColName )
		{
			SqliteError err;

			//if (parent_conn.Version == 3) 
			//{
			err = (SqliteError)Sqlite3.sqlite3_step( pStmt );

			if ( err == SqliteError.ERROR )
				throw new SqliteExecutionException(parent_conn.Handle2.errCode, GetError3() + "\n" + pStmt.zErrMsg );

			pazValue = IntPtr.Zero;
			pazColName = IntPtr.Zero; // not used for v=3
			cols = Sqlite3.sqlite3_column_count( pStmt );

			/*
			}
			else 
			{
			err = (SqliteError)Sqlite3.sqlite3_step(pStmt, out cols, out pazValue, out pazColName);
			if (err == SqliteError.ERROR)
			throw new SqliteExecutionException ();
			}
			*/
			if ( err == SqliteError.BUSY )
				throw new SqliteBusyException();

			if ( err == SqliteError.MISUSE )
				throw new SqliteExecutionException();

			// err is either ROW or DONE.
			return err == SqliteError.ROW;
		}
示例#9
0
		private void GetNextStatement( string pzStart, ref string pzTail, ref Sqlite3.Vdbe pStmt )
		{
			SqliteError err = (SqliteError)Sqlite3.sqlite3_prepare_v2( parent_conn.Handle2, pzStart, pzStart.Length, ref pStmt, ref pzTail );
			if ( err != SqliteError.OK )
				throw new SqliteSyntaxException( parent_conn.Handle2.errCode, GetError3() );
		}
示例#10
0
        private void Bind(Sqlite3.Vdbe stmt, Object[] values)
        {
            for (int i = 0; values != null && i < values.Length; i++)
            {
                var obj = values[i];
                if (obj == null)
                    Sqlite3.sqlite3_bind_null(stmt, i + 1);
                else if (obj is Byte || obj is UInt16 || obj is SByte || obj is Int16 || obj is Int32)
                    Sqlite3.sqlite3_bind_int(stmt, i + 1, Convert.ToInt32(obj, CultureInfo.InvariantCulture));
                else if (obj is UInt32 || obj is Int64)
                    Sqlite3.sqlite3_bind_int64(stmt, i + 1, Convert.ToInt64(obj, CultureInfo.InvariantCulture));
                else if (obj is Single || obj is Double || obj is Decimal)
                    Sqlite3.sqlite3_bind_double(stmt, i + 1, Convert.ToDouble(obj, CultureInfo.InvariantCulture));
                else if (obj is String)
                    Sqlite3.sqlite3_bind_text(stmt, i + 1, (String)obj, ((String)obj).Length, null);
                else if (obj is MutableString)
                    Sqlite3.sqlite3_bind_text(stmt, i + 1, obj.ToString(), ((MutableString)obj).Length, null);
                else if (obj is byte[])
                    Sqlite3.sqlite3_bind_blob(stmt, i + 1, (byte[])obj, ((byte[])obj).Length, null);
                else if (obj is RubySymbol)
                {
                    String val = ((RubySymbol)obj).ToString();
                    Sqlite3.sqlite3_bind_text(stmt, i + 1, val, val.Length, null);
                }
                else if (obj is Boolean)
                {
                    String val = ((Boolean)obj) ? "true" : "false";
                    Sqlite3.sqlite3_bind_text(stmt, i + 1, val, val.Length, null);
                }
                else
                {
                    String val = obj.ToString();
                    Sqlite3.sqlite3_bind_text(stmt, i + 1, val, val.Length, null);
                }

                checkError();
            }
        }
 /// <summary>
 /// Gets rows affected
 /// </summary>
 /// <param name="query"></param>
 public int RowsAffected()
 {
     return(Sqlite3.sqlite3_changes(db));
 }
 private static void ExecuteCommand(Sqlite3.sqlite3 db, string command)
 {
   int rc;
   Sqlite3.Vdbe vm = null;
   if (Sqlite3.sqlite3_prepare_v2(db, command, command.Length, ref vm, 0) != Sqlite3.SQLITE_OK)
   {
     throw new InvalidOperationException(string.Format("Query failed ({0}), message: {1}.", db.errCode, Sqlite3.sqlite3_errmsg(db)));
   }
   rc = Sqlite3.sqlite3_step(vm);
   if (rc != Sqlite3.SQLITE_DONE && rc != Sqlite3.SQLITE_ROW)
   {
     throw new InvalidOperationException(string.Format("Query failed ({0}), message: {1}.", db.errCode, Sqlite3.sqlite3_errmsg(db)));
   }
   Sqlite3.sqlite3_finalize(vm);
 }
示例#13
0
 /// <summary>
 /// Reset statement
 /// </summary>
 public void Reset()
 {
     // Reset the statment so it's ready to use again
     Sqlite3.sqlite3_reset(vm);
 }
示例#14
0
 /// <summary>
 /// Returns Result column as Text
 /// </summary>
 /// <returns>Result column</returns>
 public string Result_Text(int index)
 {
     return(Sqlite3.sqlite3_column_text(vm, index));
 }
示例#15
0
 // Note: added by jokedst
 public double Result_Double(int index)
 {
     return(Sqlite3.sqlite3_column_double(vm, index));
 }
示例#16
0
 /// <summary>
 /// Returns Result column as Long
 /// </summary>
 /// <returns>Result column</returns>
 public long Result_Long(int index)
 {
     return(Sqlite3.sqlite3_column_int64(vm, index));
 }
示例#17
0
 /// <summary>
 /// Execute statement
 /// </summary>
 /// <returns>LastResult</returns>
 public int ExecuteStep()
 {
     // Execute the statement
     LastResult = Sqlite3.sqlite3_step(vm);
     return(LastResult);
 }
示例#18
0
        // private function for creating Column Names
        // Return number of colums read
        private int ReadColumnNames(Vdbe vm, DataTable table)
        {
            String columnName = "";
            int    columnType = 0;
            // returns number of columns returned by statement
            int columnCount =
#if NET_35
                Sqlite3.ColumnCount
#else
                Sqlite3.sqlite3_column_count
#endif
                    (vm);

            object[] columnValues = new object[columnCount];

            try
            {
                // reads columns one by one
                for (int i = 0; i < columnCount; i++)
                {
                    columnName =
#if NET_35
                        Sqlite3.ColumnName
#else
                        Sqlite3.sqlite3_column_name
#endif
                            (vm, i);

                    columnType =
#if NET_35
                        Sqlite3.ColumnType
#else
                        Sqlite3.sqlite3_column_type
#endif
                            (vm, i);

                    switch (columnType)
                    {
                    case Sqlite3.SQLITE_INTEGER:
                    {
                        // adds new integer column to table
                        table.Columns.Add(columnName, Type.GetType("System.Int64"));
                        break;
                    }

                    case Sqlite3.SQLITE_FLOAT:
                    {
                        table.Columns.Add(columnName, Type.GetType("System.Double"));
                        break;
                    }

                    case Sqlite3.SQLITE_TEXT:
                    {
                        table.Columns.Add(columnName, Type.GetType("System.String"));
                        break;
                    }

                    case Sqlite3.SQLITE_BLOB:
                    {
                        table.Columns.Add(columnName, Type.GetType("System.byte[]"));
                        break;
                    }

                    default:
                    {
                        table.Columns.Add(columnName, Type.GetType("System.String"));
                        break;
                    }
                    }
                }
            }
            catch
            {
                return(0);
            }
            return(table.Columns.Count);
        }
示例#19
0
        // private function for reading rows and creating table and columns
        private int ReadNextRow(Vdbe vm, DataTable table)
        {
            int columnCount = table.Columns.Count;

            if (columnCount == 0)
            {
                if ((columnCount = ReadColumnNames(vm, table)) == 0)
                {
                    return(Sqlite3.SQLITE_ERROR);
                }
            }

            int resultType;

            if ((resultType =
#if NET_35
                     Sqlite3.Step
#else
                     Sqlite3.sqlite3_step
#endif
                         (vm)) == Sqlite3.SQLITE_ROW)
            {
                object[] columnValues = new object[columnCount];

                for (int i = 0; i < columnCount; i++)
                {
                    int columnType =
#if NET_35
                        Sqlite3.ColumnType
#else
                        Sqlite3.sqlite3_column_type
#endif
                            (vm, i);

                    switch (columnType)
                    {
                    case Sqlite3.SQLITE_INTEGER:
                    {
                        table.Columns[i].DataType = typeof(Int64);
                        columnValues[i]           =
#if NET_35
                            Sqlite3.ColumnInt
#else
                            Sqlite3.sqlite3_column_int
#endif
                                (vm, i);

                        break;
                    }

                    case Sqlite3.SQLITE_FLOAT:
                    {
                        table.Columns[i].DataType = typeof(Double);
                        columnValues[i]           =
#if NET_35
                            Sqlite3.ColumnDouble
#else
                            Sqlite3.sqlite3_column_double
#endif
                                (vm, i);

                        break;
                    }

                    case Sqlite3.SQLITE_TEXT:
                    {
                        table.Columns[i].DataType = typeof(String);
                        columnValues[i]           =
#if NET_35
                            Sqlite3.ColumnText
#else
                            Sqlite3.sqlite3_column_text
#endif
                                (vm, i);

                        break;
                    }

                    case Sqlite3.SQLITE_BLOB:
                    {
                        table.Columns[i].DataType = typeof(Byte[]);
                        columnValues[i]           =
#if NET_35
                            Sqlite3.ColumnBlob
#else
                            Sqlite3.sqlite3_column_blob
#endif
                                (vm, i);

                        break;
                    }

                    default:
                    {
                        table.Columns[i].DataType = null;
                        columnValues[i]           = "";
                        break;
                    }
                    }
                }
                table.Rows.Add(columnValues);
            }
            return(resultType);
        }
示例#20
0
 public static void SyncBlob_DeleteSchemaCallback(Sqlite3.sqlite3_context dbContext, int nArgs, Sqlite3.Mem[] Args)
 {
     String value = Sqlite3.sqlite3_value_text(Args[0]);
     if (value == null) return;
     String strFilePath = RHODESAPP().resolveDBFilesPath(value);
     if (strFilePath != "")
         CRhoFile.deleteFile(strFilePath);
 }
示例#21
0
 /// <summary>
 /// Closes statement
 /// </summary>
 public void Close()
 {
     Sqlite3.sqlite3_finalize(vm);
 }
示例#22
0
 public CSqliteResult(Sqlite3.Vdbe stmt, boolean bNoCopy)
 {
     m_bNoCopy = bNoCopy;
     m_st = stmt;
 }
示例#23
0
 // Note: added by jokedst
 /// <summary>
 /// Gets column name
 /// </summary>
 /// <param name="index">index of column</param>
 /// <returns>Name of column</returns>
 public string ColumnName(int index)
 {
     return(Sqlite3.sqlite3_column_name(vm, index));
 }
示例#24
0
            private static void callUserFunction(Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] argv)
            {
                object[] data = (object[])Sqlite3.sqlite3_user_data(ctx);
                CodeContext context = (CodeContext)data[0];
                object func = data[1];

                object[] args = buildPyParams(context, ctx, argc, argv);

                try
                {
                    object result = PythonCalls.CallWithKeywordArgs(context, func, args, emptyKwargs);
                    setResult(ctx, result);
                }
                catch(Exception)
                {
                    Sqlite3.sqlite3_result_error(ctx, "user-defined function raised exception", -1);
                }
            }
示例#25
0
            private static object[] buildPyParams(CodeContext context, Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] argv)
            {
                object[] args = new object[argc];

                for(int i = 0; i < argc; ++i)
                {
                    sqlite3_value cur_value = argv[i];
                    object cur_py_value = null;

                    switch(Sqlite3.sqlite3_value_type(cur_value))
                    {
                        case Sqlite3.SQLITE_INTEGER:
                            cur_py_value = (int)Sqlite3.sqlite3_value_int64(cur_value);
                            break;

                        case Sqlite3.SQLITE_FLOAT:
                            cur_py_value = Sqlite3.sqlite3_value_double(cur_value);
                            break;

                        case Sqlite3.SQLITE_TEXT:
                            cur_py_value = Sqlite3.sqlite3_value_text(cur_value);
                            break;

                        case Sqlite3.SQLITE_BLOB:
                            byte[] result = Sqlite3.sqlite3_value_blob(cur_value);
                            PythonBuffer buffer = new PythonBuffer(context, result);
                            cur_py_value = buffer;
                            break;

                        case Sqlite3.SQLITE_NULL:
                        default:
                            cur_py_value = null;
                            break;
                    }

                    args[i] = cur_py_value;
                }

                return args;
            }
 public SQliteResultSet(ref Sqlite3.dxCallback callback)
 {
     result = new List<object[]>();
     callback = sqcallback;
 }
示例#27
0
 private static void setResult(Sqlite3.sqlite3_context ctx, object result)
 {
     if(result == null)
         Sqlite3.sqlite3_result_null(ctx);
     else if(result is bool)
         Sqlite3.sqlite3_result_int64(ctx, ((bool)result) ? 1 : 0);
     else if(result is int)
         Sqlite3.sqlite3_result_int64(ctx, (int)result);
     else if(result is long)
         Sqlite3.sqlite3_result_int64(ctx, (long)result);
     else if(result is Microsoft.Scripting.Math.BigInteger)
         Sqlite3.sqlite3_result_int64(ctx, ((Microsoft.Scripting.Math.BigInteger)result).ToInt64());
     else if(result is float)
         Sqlite3.sqlite3_result_double(ctx, (float)result);
     else if(result is double)
         Sqlite3.sqlite3_result_double(ctx, (double)result);
     else if(result is string)
         Sqlite3.sqlite3_result_text(ctx, (string)result, -1, Sqlite3.SQLITE_TRANSIENT);
     else if(result is byte[])
     {
         byte[] b = (byte[])result;
         string s = Latin1.GetString(b, 0, b.Length);
         Sqlite3.sqlite3_result_blob(ctx, s, s.Length, Sqlite3.SQLITE_TRANSIENT);
     }
     else if(result is PythonBuffer)
     {
         PythonBuffer buffer = (PythonBuffer)result;
         string s = buffer.__getslice__(0, null).ToString();
         Sqlite3.sqlite3_result_blob(ctx, s, s.Length, Sqlite3.SQLITE_TRANSIENT);
     }
     else
     {
         // TODO raise error
     }
 }
示例#28
0
		private void BindParameters3( Sqlite3.Vdbe pStmt )
		{
			if ( sql_params == null )
				return;
			if ( sql_params.Count == 0 )
				return;

			int pcount = Sqlite3.sqlite3_bind_parameter_count( pStmt );

			for ( int i = 1; i <= pcount; i++ )
			{
				String name = Sqlite3.sqlite3_bind_parameter_name( pStmt, i );

				SqliteParameter param = null;
        if ( !string.IsNullOrEmpty( name ) )
          param = sql_params[name] as SqliteParameter;
				else
					param = sql_params[i - 1] as SqliteParameter;

				if ( param.Value == null )
				{
					Sqlite3.sqlite3_bind_null( pStmt, i );
					continue;
				}

				Type ptype = param.Value.GetType();
				if ( ptype.IsEnum )
					ptype = Enum.GetUnderlyingType( ptype );

				SqliteError err;

				if ( ptype.Equals( typeof( String ) ) )
				{
					String s = (String)param.Value;
					err = (SqliteError)Sqlite3.sqlite3_bind_text( pStmt, i, s, -1, null );
				} else if ( ptype.Equals( typeof( DBNull ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_null( pStmt, i );
				} else if ( ptype.Equals( typeof( Boolean ) ) )
				{
					bool b = (bool)param.Value;
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, b ? 1 : 0 );
				} else if ( ptype.Equals( typeof( Byte ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, (Byte)param.Value );
				} else if ( ptype.Equals( typeof( Char ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, (Char)param.Value );
				} else if ( ptype.IsEnum )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, (Int32)param.Value );
				} else if ( ptype.Equals( typeof( Int16 ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, (Int16)param.Value );
				} else if ( ptype.Equals( typeof( Int32 ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, (Int32)param.Value );
				} else if ( ptype.Equals( typeof( SByte ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, (SByte)param.Value );
				} else if ( ptype.Equals( typeof( UInt16 ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int( pStmt, i, (UInt16)param.Value );
				} else if ( ptype.Equals( typeof( DateTime ) ) )
				{
					DateTime dt = (DateTime)param.Value;
					err = (SqliteError)Sqlite3.sqlite3_bind_text( pStmt, i, dt.ToString( "yyyy-MM-dd HH:mm:ss.fff" ), -1, null );
				} else if ( ptype.Equals( typeof( Decimal ) ) )
				{
					string val = ( (Decimal)param.Value ).ToString( CultureInfo.InvariantCulture );
					err = (SqliteError)Sqlite3.sqlite3_bind_text( pStmt, i, val, val.Length, null );
				} else if ( ptype.Equals( typeof( Double ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_double( pStmt, i, (Double)param.Value );
				} else if ( ptype.Equals( typeof( Single ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_double( pStmt, i, (Single)param.Value );
				} else if ( ptype.Equals( typeof( UInt32 ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int64( pStmt, i, (UInt32)param.Value );
				} else if ( ptype.Equals( typeof( Int64 ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_int64( pStmt, i, (Int64)param.Value );
				} else if ( ptype.Equals( typeof( Byte[] ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_blob( pStmt, i, (byte[])param.Value, ( (byte[])param.Value ).Length, null );
				} else if ( ptype.Equals( typeof( Guid ) ) )
				{
					err = (SqliteError)Sqlite3.sqlite3_bind_text( pStmt, i, param.Value.ToString(), param.Value.ToString().Length, null );
				} else
				{
					throw new ApplicationException( "Unknown Parameter Type" );
				}
				if ( err != SqliteError.OK )
				{
					throw new ApplicationException( "Sqlite error in bind " + err );
				}
			}
		}
 public DbHandle(Sqlite3.sqlite3 internalDbHandle) : this()
 {
     InternalDbHandle = internalDbHandle;
 }
示例#30
0
		// Executes a statement and ignores its result.
		private void ExecuteStatement( Sqlite3.Vdbe pStmt )
		{
			int cols;
			IntPtr pazValue, pazColName;
			ExecuteStatement( pStmt, out cols, out pazValue, out pazColName );
		}
示例#31
0
        internal static Exception GetSqliteError(Sqlite3.sqlite3 db, Sqlite3.Vdbe st)
        {
            /* SQLite often doesn't report anything useful, unless you reset the statement first */
            if(st != null)
            {
                Sqlite3.sqlite3_reset(st);
            }

            int errorcode = Sqlite3.sqlite3_errcode(db);
            string errmsg = Sqlite3.sqlite3_errmsg(db);

            switch(errorcode)
            {
                case SQLITE_OK:
                    return null;

                case Sqlite3.SQLITE_INTERNAL:
                case Sqlite3.SQLITE_NOTFOUND:
                    return MakeInternalError(errmsg);

                case Sqlite3.SQLITE_NOMEM:
                    return new OutOfMemoryException();

                case Sqlite3.SQLITE_ERROR:
                case Sqlite3.SQLITE_PERM:
                case Sqlite3.SQLITE_ABORT:
                case Sqlite3.SQLITE_BUSY:
                case Sqlite3.SQLITE_LOCKED:
                case Sqlite3.SQLITE_READONLY:
                case Sqlite3.SQLITE_INTERRUPT:
                case Sqlite3.SQLITE_IOERR:
                case Sqlite3.SQLITE_FULL:
                case Sqlite3.SQLITE_CANTOPEN:
                case Sqlite3.SQLITE_PROTOCOL:
                case Sqlite3.SQLITE_EMPTY:
                case Sqlite3.SQLITE_SCHEMA:
                    return MakeOperationalError(errmsg);

                case Sqlite3.SQLITE_CORRUPT:
                    return MakeDatabaseError(errmsg);

                case Sqlite3.SQLITE_TOOBIG:
                    return MakeDataError(errmsg);

                case Sqlite3.SQLITE_CONSTRAINT:
                case Sqlite3.SQLITE_MISMATCH:
                    return MakeIntegrityError(errmsg);

                case Sqlite3.SQLITE_MISUSE:
                    return MakeProgrammingError(errmsg);

                default:
                    return MakeDatabaseError(errmsg);
            }
        }
示例#32
0
		internal void ReadpVm (Sqlite3.Vdbe pVm, int version, SqliteCommand cmd)
		{
			int pN;
			IntPtr pazValue;
			IntPtr pazColName;
			bool first = true;
			
			int[] declmode = null;

			while (true) {
				bool hasdata = cmd.ExecuteStatement(pVm, out pN, out pazValue, out pazColName);
			
				// For the first row, get the column information
				if (first) {
					first = false;
					
					if (version == 3) {
						// A decltype might be null if the type is unknown to sqlite.
						decltypes = new string[pN];
						declmode = new int[pN]; // 1 == integer, 2 == datetime
						for (int i = 0; i < pN; i++) {
							string decl = Sqlite3.sqlite3_column_decltype (pVm, i);
							if (decl != null) {
								decltypes[i] = decl.ToLower(System.Globalization.CultureInfo.InvariantCulture);
								if (decltypes[i] == "int" || decltypes[i] == "integer")
									declmode[i] = 1;
								else if (decltypes[i] == "date" || decltypes[i] == "datetime")
									declmode[i] = 2;
							}
						}
					}
					
					columns = new string[pN];	
					for (int i = 0; i < pN; i++) {
						string colName;
						//if (version == 2) {
						//	IntPtr fieldPtr = Marshal.ReadIntPtr (pazColName, i*IntPtr.Size);
						//	colName = Sqlite.HeapToString (fieldPtr, ((SqliteConnection)cmd.Connection).Encoding);
						//} else {
							colName = Sqlite3.sqlite3_column_name (pVm, i);
						//}
						columns[i] = colName;
						column_names_sens [colName] = i;
						column_names_insens [colName] = i;
					}
				}

				if (!hasdata) break;
				
				object[] data_row = new object [pN];
				for (int i = 0; i < pN; i++) {
					/*
                    if (version == 2) {
						IntPtr fieldPtr = Marshal.ReadIntPtr (pazValue, i*IntPtr.Size);
						data_row[i] = Sqlite.HeapToString (fieldPtr, ((SqliteConnection)cmd.Connection).Encoding);
					} else {
                    */
						switch (Sqlite3.sqlite3_column_type (pVm, i)) {
							case 1:
								long val = Sqlite3.sqlite3_column_int64 (pVm, i);
							
								// If the column was declared as an 'int' or 'integer', let's play
								// nice and return an int (version 3 only).
								if (declmode[i] == 1 && val >= int.MinValue && val <= int.MaxValue)
									data_row[i] = (int)val;
								
								// Or if it was declared a date or datetime, do the reverse of what we
								// do for DateTime parameters.
								else if (declmode[i] == 2)
									data_row[i] = DateTime.FromFileTime(val);								
								else
									data_row[i] = val;
									
								break;
							case 2:
								data_row[i] = Sqlite3.sqlite3_column_double (pVm, i);
								break;
							case 3:
								data_row[i] = Sqlite3.sqlite3_column_text (pVm, i);
								
								// If the column was declared as a 'date' or 'datetime', let's play
								// nice and return a DateTime (version 3 only).
								if (declmode[i] == 2)
									if (data_row[i] == null) data_row[i] = null;
									else data_row[i] = DateTime.Parse((string)data_row[i], System.Globalization.CultureInfo.InvariantCulture);
								break;
							case 4:
								int blobbytes = Sqlite3.sqlite3_column_bytes16 (pVm, i);
								byte[] blob = Sqlite3.sqlite3_column_blob(pVm, i);
								//byte[] blob = new byte[blobbytes];
								//Marshal.Copy (blobptr, blob, 0, blobbytes);
								data_row[i] = blob;
								break;
							case 5:
								data_row[i] = null;
								break;
							default:
								throw new Exception ("FATAL: Unknown sqlite3_column_type");
						//}
					}
				}
				
				rows.Add (data_row);
			}
		}
 private void GetNextStatement( string pzStart, ref string pzTail, ref Sqlite3.Vdbe pStmt )
 {
   UTF8Encoding encoding = new UTF8Encoding();
   SqliteError err = (SqliteError)Sqlite3.sqlite3_prepare( parent_conn.Handle2, pzStart, pzStart.Length, ref pStmt, ref pzTail );
   if ( err != SqliteError.OK )
     throw new SqliteSyntaxException( GetError3() );
 }
示例#34
0
                public void stepCallback(Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] param)
                {
                    if(instance == null)
                    {
                        try
                        {
                            instance = PythonCalls.Call(context, aggregate_class);
                        }
                        catch(Exception)
                        {
                            Sqlite3.sqlite3_result_error(ctx, "user-defined aggregate's '__init__' method raised error", -1);
                            return;
                        }
                    }

                    try
                    {
                        object step = context.LanguageContext.Operations.GetMember(instance, "step");
                        object[] args = buildPyParams(context, ctx, argc, param);

                        PythonCalls.CallWithKeywordArgs(context, step, args, new Dictionary<object, object>());
                    }
                    catch(Exception e)
                    {
                        if(e is MissingMemberException)
                            throw;

                        Sqlite3.sqlite3_result_error(ctx, "user-defined aggregate's 'step' method raised error", -1);
                    }
                }
示例#35
0
    public static void SyncBlob_UpdateSchemaCallback(Sqlite3.sqlite3_context dbContext, int nArgs, Sqlite3.Mem[] Args)
    {
        String szOldValue = Sqlite3.sqlite3_value_text(Args[0]);
        String szNewValue = Sqlite3.sqlite3_value_text(Args[1]);
        
        if ( szOldValue == szNewValue || szOldValue == null )
            return;

        if ( szOldValue != null && szNewValue != null &&  szOldValue == szNewValue )
            return;

        if (szOldValue != null)
        {
            String strFilePath = RHODESAPP().resolveDBFilesPath(szOldValue);
            CRhoFile.deleteFile(strFilePath);
        }
    }
 public DbStatement(Sqlite3.Vdbe internalStmt)
     : this()
 {
     InternalStmt = internalStmt;
 }
示例#37
0
                public void finalCallback(Sqlite3.sqlite3_context ctx)
                {
                    if(instance == null)
                        return;

                    try
                    {
                        object function_result = context.LanguageContext.Operations.InvokeMember(instance, "finalize");
                        setResult(ctx, function_result);
                    }
                    catch(Exception)
                    {
                        Sqlite3.sqlite3_result_error(ctx, "user-defined aggregate's 'finalize' method raised error", -1);
                    }
                }