Пример #1
0
        internal override void GetIndexColumnExtendedInfo(string database, string index, string column, out int sortMode, out int onError, out string collationSequence)
        {
            IntPtr ptr;
            int    num;
            int    errorCode = UnsafeNativeMethods.sqlite3_index_column_info_interop((IntPtr)this._sql, SQLiteConvert.ToUTF8(database), SQLiteConvert.ToUTF8(index), SQLiteConvert.ToUTF8(column), out sortMode, out onError, out ptr, out num);

            if (errorCode != 0)
            {
                throw new SQLiteException(errorCode, "");
            }
            collationSequence = SQLiteConvert.UTF8ToString(ptr, num);
        }
Пример #2
0
        internal override CollationSequence GetCollationSequence(SQLiteFunction func, IntPtr context)
        {
            int num;
            int num2;
            int num3;
            CollationSequence sequence     = new CollationSequence();
            IntPtr            nativestring = UnsafeNativeMethods.sqlite3_context_collseq(context, out num2, out num3, out num);

            sequence.Name     = SQLiteConvert.UTF8ToString(nativestring, num);
            sequence.Type     = (CollationTypeEnum)num2;
            sequence._func    = func;
            sequence.Encoding = (CollationEncodingEnum)num3;
            return(sequence);
        }
Пример #3
0
        internal override string ColumnType(SQLiteStatement stmt, int index, out TypeAffinity nAffinity)
        {
            int    num;
            IntPtr nativestring = UnsafeNativeMethods.sqlite3_column_decltype_interop((IntPtr)stmt._sqlite_stmt, index, out num);

            nAffinity = this.ColumnAffinity(stmt, index);
            if (nativestring != IntPtr.Zero)
            {
                return(SQLiteConvert.UTF8ToString(nativestring, num));
            }
            string[] typeDefinitions = stmt.TypeDefinitions;
            if (((typeDefinitions != null) && (index < typeDefinitions.Length)) && (typeDefinitions[index] != null))
            {
                return(typeDefinitions[index]);
            }
            return(string.Empty);
        }
Пример #4
0
        internal override void ColumnMetaData(string dataBase, string table, string column, out string dataType, out string collateSequence, out bool notNull, out bool primaryKey, out bool autoIncrement)
        {
            IntPtr ptr;
            IntPtr ptr2;
            int    num;
            int    num2;
            int    num3;
            int    num5;
            int    num6;
            int    errorCode = UnsafeNativeMethods.sqlite3_table_column_metadata_interop((IntPtr)this._sql, SQLiteConvert.ToUTF8(dataBase), SQLiteConvert.ToUTF8(table), SQLiteConvert.ToUTF8(column), out ptr, out ptr2, out num, out num2, out num3, out num5, out num6);

            if (errorCode > 0)
            {
                throw new SQLiteException(errorCode, this.SQLiteLastError());
            }
            dataType        = SQLiteConvert.UTF8ToString(ptr, num5);
            collateSequence = SQLiteConvert.UTF8ToString(ptr2, num6);
            notNull         = num == 1;
            primaryKey      = num2 == 1;
            autoIncrement   = num3 == 1;
        }
Пример #5
0
        internal static string SQLiteLastError(SQLiteConnectionHandle db)
        {
            int num;

            return(SQLiteConvert.UTF8ToString(UnsafeNativeMethods.sqlite3_errmsg_interop((IntPtr)db, out num), num));
        }
Пример #6
0
        internal override SQLiteStatement Prepare(SQLiteConnection cnn, string strSql, SQLiteStatement previous, uint timeoutMS, out string strRemain)
        {
            SQLiteStatement statement2;
            IntPtr          zero      = IntPtr.Zero;
            IntPtr          ptrRemain = IntPtr.Zero;
            int             nRemain   = 0;
            int             errorCode = 0x11;
            int             num3      = 0;

            byte[]          buffer    = SQLiteConvert.ToUTF8(strSql);
            string          typedefs  = null;
            SQLiteStatement statement = null;
            Random          random    = null;
            uint            tickCount = (uint)Environment.TickCount;
            GCHandle        handle    = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            IntPtr          pSql      = handle.AddrOfPinnedObject();

            try
            {
                while ((((errorCode == 0x11) || (errorCode == 6)) || (errorCode == 5)) && (num3 < 3))
                {
                    errorCode = UnsafeNativeMethods.sqlite3_prepare_interop((IntPtr)this._sql, pSql, buffer.Length - 1, out zero, out ptrRemain, out nRemain);
                    if (errorCode == 0x11)
                    {
                        num3++;
                    }
                    else
                    {
                        if (errorCode == 1)
                        {
                            if (string.Compare(this.SQLiteLastError(), "near \"TYPES\": syntax error", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                int index = strSql.IndexOf(';');
                                if (index == -1)
                                {
                                    index = strSql.Length - 1;
                                }
                                typedefs  = strSql.Substring(0, index + 1);
                                strSql    = strSql.Substring(index + 1);
                                strRemain = "";
                                while ((statement == null) && (strSql.Length > 0))
                                {
                                    statement = this.Prepare(cnn, strSql, previous, timeoutMS, out strRemain);
                                    strSql    = strRemain;
                                }
                                if (statement != null)
                                {
                                    statement.SetTypes(typedefs);
                                }
                                return(statement);
                            }
                            if (this._buildingSchema || (string.Compare(this.SQLiteLastError(), 0, "no such table: TEMP.SCHEMA", 0, 0x1a, StringComparison.OrdinalIgnoreCase) != 0))
                            {
                                continue;
                            }
                            strRemain            = "";
                            this._buildingSchema = true;
                            try
                            {
                                ISQLiteSchemaExtensions service = ((IServiceProvider)SQLiteFactory.Instance).GetService(typeof(ISQLiteSchemaExtensions)) as ISQLiteSchemaExtensions;
                                if (service != null)
                                {
                                    service.BuildTempSchema(cnn);
                                }
                                while ((statement == null) && (strSql.Length > 0))
                                {
                                    statement = this.Prepare(cnn, strSql, previous, timeoutMS, out strRemain);
                                    strSql    = strRemain;
                                }
                                return(statement);
                            }
                            finally
                            {
                                this._buildingSchema = false;
                            }
                        }
                        switch (errorCode)
                        {
                        case 6:
                        case 5:
                            if (random == null)
                            {
                                random = new Random();
                            }
                            if ((Environment.TickCount - tickCount) > timeoutMS)
                            {
                                throw new SQLiteException(errorCode, this.SQLiteLastError());
                            }
                            Thread.Sleep(random.Next(1, 150));
                            break;
                        }
                    }
                }
                if (errorCode > 0)
                {
                    throw new SQLiteException(errorCode, this.SQLiteLastError());
                }
                strRemain = SQLiteConvert.UTF8ToString(ptrRemain, nRemain);
                if (zero != IntPtr.Zero)
                {
                    statement = new SQLiteStatement(this, zero, strSql.Substring(0, strSql.Length - strRemain.Length), previous);
                }
                statement2 = statement;
            }
            finally
            {
                handle.Free();
            }
            return(statement2);
        }
Пример #7
0
        internal override string GetText(SQLiteStatement stmt, int index)
        {
            int num;

            return(SQLiteConvert.UTF8ToString(UnsafeNativeMethods.sqlite3_column_text_interop((IntPtr)stmt._sqlite_stmt, index, out num), num));
        }
Пример #8
0
        internal override string GetParamValueText(IntPtr ptr)
        {
            int num;

            return(SQLiteConvert.UTF8ToString(UnsafeNativeMethods.sqlite3_value_text_interop(ptr, out num), num));
        }
Пример #9
0
        internal override string ColumnOriginalName(SQLiteStatement stmt, int index)
        {
            int num;

            return(SQLiteConvert.UTF8ToString(UnsafeNativeMethods.sqlite3_column_origin_name_interop((IntPtr)stmt._sqlite_stmt, index, out num), num));
        }
Пример #10
0
        internal override string Bind_ParamName(SQLiteStatement stmt, int index)
        {
            int num;

            return(SQLiteConvert.UTF8ToString(UnsafeNativeMethods.sqlite3_bind_parameter_name_interop((IntPtr)stmt._sqlite_stmt, index, out num), num));
        }