protected virtual void Dispose(bool disposing)
 {
     try
     {
         if (!this.disposed && this.statement != IntPtr.Zero)
         {
             try
             {
                 if (HelperMethods.LogPrepare(this.GetFlags()))
                 {
                     CultureInfo currentCulture = CultureInfo.CurrentCulture;
                     object[]    objArray       = new object[] { (disposing ? "disposed" : "finalized"), this.statement };
                     SQLiteLog.LogMessage(SQLiteErrorCode.Misuse, HelperMethods.StringFormat(currentCulture, "Connection lock object was {0} with statement {1}", objArray));
                 }
             }
             catch
             {
             }
         }
     }
     finally
     {
         this.disposed = true;
     }
 }
예제 #2
0
        private static void LogEventHandler(object sender, LogEventArgs e)
        {
            if (e == null)
            {
                return;
            }
            string message = e.Message;

            if (message != null)
            {
                message = message.Trim();
                if (message.Length == 0)
                {
                    message = "<empty>";
                }
            }
            else
            {
                message = "<null>";
            }
            object errorCode = e.ErrorCode;
            string str       = "error";

            if (errorCode as SQLiteErrorCode? != SQLiteErrorCode.Ok || errorCode is int)
            {
                SQLiteErrorCode sQLiteErrorCode = (SQLiteErrorCode)((int)(errorCode ?? -1));
                sQLiteErrorCode &= SQLiteErrorCode.NonExtendedMask;
                if (sQLiteErrorCode == SQLiteErrorCode.Ok)
                {
                    str = "message";
                }
                else if (sQLiteErrorCode == SQLiteErrorCode.Notice)
                {
                    str = "notice";
                }
                else if (sQLiteErrorCode == SQLiteErrorCode.Warning)
                {
                    str = "warning";
                }
                else if (sQLiteErrorCode == SQLiteErrorCode.Row || sQLiteErrorCode == SQLiteErrorCode.Done)
                {
                    str = "data";
                }
            }
            else if (errorCode == null)
            {
                str = "trace";
            }
            if (errorCode == null || object.ReferenceEquals(errorCode, string.Empty))
            {
                CultureInfo currentCulture = CultureInfo.CurrentCulture;
                object[]    objArray       = new object[] { str, message };
                Trace.WriteLine(HelperMethods.StringFormat(currentCulture, "SQLite {0}: {1}", objArray));
                return;
            }
            CultureInfo cultureInfo = CultureInfo.CurrentCulture;

            object[] objArray1 = new object[] { str, errorCode, message };
            Trace.WriteLine(HelperMethods.StringFormat(cultureInfo, "SQLite {0} ({1}): {2}", objArray1));
        }
        static SQLiteModuleCommon()
        {
            CultureInfo invariantCulture = CultureInfo.InvariantCulture;

            object[] name = new object[] { typeof(SQLiteModuleCommon).Name };
            SQLiteModuleCommon.declareSql = HelperMethods.StringFormat(invariantCulture, "CREATE TABLE {0}(x);", name);
        }
예제 #4
0
        internal SQLiteStatement(SQLiteBase sqlbase, SQLiteConnectionFlags flags, SQLiteStatementHandle stmt, string strCommand, SQLiteStatement previous)
        {
            this._sql          = sqlbase;
            this._sqlite_stmt  = stmt;
            this._sqlStatement = strCommand;
            this._flags        = flags;
            int num  = 0;
            int num1 = this._sql.Bind_ParamCount(this, this._flags);

            if (num1 > 0)
            {
                if (previous != null)
                {
                    num = previous._unnamedParameters;
                }
                this._paramNames  = new string[num1];
                this._paramValues = new SQLiteParameter[num1];
                for (int i = 0; i < num1; i++)
                {
                    string str = this._sql.Bind_ParamName(this, this._flags, i + 1);
                    if (string.IsNullOrEmpty(str))
                    {
                        CultureInfo invariantCulture = CultureInfo.InvariantCulture;
                        object[]    objArray         = new object[] { num };
                        str = HelperMethods.StringFormat(invariantCulture, ";{0}", objArray);
                        num++;
                        this._unnamedParameters++;
                    }
                    this._paramNames[i]  = str;
                    this._paramValues[i] = null;
                }
            }
        }
예제 #5
0
        private static string GetStockErrorMessage(SQLiteErrorCode errorCode, string message)
        {
            CultureInfo currentCulture = CultureInfo.CurrentCulture;

            object[] errorString = new object[] { SQLiteException.GetErrorString(errorCode), Environment.NewLine, message };
            return(HelperMethods.StringFormat(currentCulture, "{0}{1}{2}", errorString).Trim());
        }
        private System.Data.IsolationLevel GetSystemDataIsolationLevel(SQLiteConnection connection, Transaction transaction, System.Data.IsolationLevel defaultIsolationLevel, bool throwOnUnavailable, bool throwOnUnsupported)
        {
            if (transaction == null)
            {
                if (connection != null)
                {
                    return(connection.GetDefaultIsolationLevel());
                }
                if (throwOnUnavailable)
                {
                    throw new InvalidOperationException("isolation level is unavailable");
                }
                return(defaultIsolationLevel);
            }
            System.Transactions.IsolationLevel isolationLevel = transaction.IsolationLevel;
            switch (isolationLevel)
            {
            case System.Transactions.IsolationLevel.Serializable:
            {
                return(System.Data.IsolationLevel.Serializable);
            }

            case System.Transactions.IsolationLevel.RepeatableRead:
            {
                return(System.Data.IsolationLevel.RepeatableRead);
            }

            case System.Transactions.IsolationLevel.ReadCommitted:
            {
                return(System.Data.IsolationLevel.ReadCommitted);
            }

            case System.Transactions.IsolationLevel.ReadUncommitted:
            {
                return(System.Data.IsolationLevel.ReadUncommitted);
            }

            case System.Transactions.IsolationLevel.Snapshot:
            {
                return(System.Data.IsolationLevel.Snapshot);
            }

            case System.Transactions.IsolationLevel.Chaos:
            {
                return(System.Data.IsolationLevel.Chaos);
            }

            case System.Transactions.IsolationLevel.Unspecified:
            {
                return(System.Data.IsolationLevel.Unspecified);
            }
            }
            if (throwOnUnsupported)
            {
                CultureInfo currentCulture = CultureInfo.CurrentCulture;
                object[]    objArray       = new object[] { isolationLevel };
                throw new InvalidOperationException(HelperMethods.StringFormat(currentCulture, "unsupported isolation level {0}", objArray));
            }
            return(defaultIsolationLevel);
        }
예제 #7
0
 protected UnsafeNativeMethods.xSessionConflict GetDelegate(SessionConflictCallback conflictCallback, object clientData)
 {
     if (conflictCallback == null)
     {
         return(null);
     }
     return((IntPtr context, SQLiteChangeSetConflictType type, IntPtr iterator) => {
         SQLiteChangeSetConflictResult sQLiteChangeSetConflictResult;
         try
         {
             ISQLiteChangeSetMetadataItem sQLiteChangeSetMetadataItem = this.CreateMetadataItem(iterator);
             if (sQLiteChangeSetMetadataItem == null)
             {
                 throw new SQLiteException("could not create metadata item");
             }
             sQLiteChangeSetConflictResult = conflictCallback(clientData, type, sQLiteChangeSetMetadataItem);
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             try
             {
                 if (HelperMethods.LogCallbackExceptions(base.GetFlags()))
                 {
                     SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(CultureInfo.CurrentCulture, "Caught exception in \"{0}\" method: {1}", new object[] { "xSessionConflict", exception }));
                 }
             }
             catch
             {
             }
             return SQLiteChangeSetConflictResult.Abort;
         }
         return sQLiteChangeSetConflictResult;
     });
 }
예제 #8
0
        internal int CompareCallback16(IntPtr ptr, int len1, IntPtr ptr1, int len2, IntPtr ptr2)
        {
            int num;

            try
            {
                num = this.Compare(SQLite3_UTF16.UTF16ToString(ptr1, len1), SQLite3_UTF16.UTF16ToString(ptr2, len2));
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                try
                {
                    if (HelperMethods.LogCallbackExceptions(this._flags))
                    {
                        CultureInfo currentCulture = CultureInfo.CurrentCulture;
                        object[]    objArray       = new object[] { "Compare (UTF16)", exception };
                        SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(currentCulture, "Caught exception in \"{0}\" method: {1}", objArray));
                    }
                }
                catch
                {
                }
                if (this._base != null && this._base.IsOpen())
                {
                    this._base.Cancel();
                }
                return(0);
            }
            return(num);
        }
예제 #9
0
 //[ReflectionPermission(SecurityAction.Assert, MemberAccess=true)]
 private object GetSQLiteProviderServicesInstance()
 {
     if (SQLiteFactory._sqliteServices == null)
     {
         string  settingValue = EntityWorker.SQLite.UnsafeNativeMethods.GetSettingValue("TypeName_SQLiteProviderServices", null);
         Version version      = base.GetType().Assembly.GetName().Version;
         if (settingValue == null)
         {
             CultureInfo invariantCulture = CultureInfo.InvariantCulture;
             string      defaultTypeName  = SQLiteFactory.DefaultTypeName;
             object[]    objArray         = new object[] { version };
             settingValue = HelperMethods.StringFormat(invariantCulture, defaultTypeName, objArray);
         }
         else
         {
             CultureInfo cultureInfo = CultureInfo.InvariantCulture;
             object[]    objArray1   = new object[] { version };
             settingValue = HelperMethods.StringFormat(cultureInfo, settingValue, objArray1);
         }
         Type type = Type.GetType(settingValue, false);
         if (type != null)
         {
             FieldInfo field = type.GetField("Instance", SQLiteFactory.DefaultBindingFlags);
             if (field != null)
             {
                 SQLiteFactory._sqliteServices = field.GetValue(null);
             }
         }
     }
     return(SQLiteFactory._sqliteServices);
 }
        protected override string GetParameterName(int parameterOrdinal)
        {
            CultureInfo invariantCulture = CultureInfo.InvariantCulture;

            object[] objArray = new object[] { parameterOrdinal };
            return(HelperMethods.StringFormat(invariantCulture, "@param{0}", objArray));
        }
예제 #11
0
        private int Filter(IntPtr context, IntPtr pTblName)
        {
            int num;

            try
            {
                num = (this.tableFilterCallback(this.tableFilterClientData, SQLiteString.StringFromUtf8IntPtr(pTblName)) ? 1 : 0);
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                try
                {
                    if (HelperMethods.LogCallbackExceptions(base.GetFlags()))
                    {
                        CultureInfo currentCulture = CultureInfo.CurrentCulture;
                        object[]    objArray       = new object[] { "xSessionFilter", exception };
                        SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(currentCulture, "Caught exception in \"{0}\" method: {1}", objArray));
                    }
                }
                catch
                {
                }
                return(0);
            }
            return(num);
        }
예제 #12
0
 protected UnsafeNativeMethods.xSessionFilter GetDelegate(SessionTableFilterCallback tableFilterCallback, object clientData)
 {
     if (tableFilterCallback == null)
     {
         return(null);
     }
     return((IntPtr context, IntPtr pTblName) => {
         int num;
         try
         {
             string str = SQLiteString.StringFromUtf8IntPtr(pTblName);
             num = (tableFilterCallback(clientData, str) ? 1 : 0);
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             try
             {
                 if (HelperMethods.LogCallbackExceptions(base.GetFlags()))
                 {
                     SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(CultureInfo.CurrentCulture, "Caught exception in \"{0}\" method: {1}", new object[] { "xSessionFilter", exception }));
                 }
             }
             catch
             {
             }
             return 0;
         }
         return num;
     });
 }
        public override SQLiteErrorCode Update(SQLiteVirtualTable table, SQLiteValue[] values, ref long rowId)
        {
            this.CheckDisposed();
            CultureInfo currentCulture = CultureInfo.CurrentCulture;

            object[] tableName = new object[] { table.TableName };
            this.SetTableError(table, HelperMethods.StringFormat(currentCulture, "virtual table \"{0}\" is read-only", tableName));
            return(SQLiteErrorCode.Error);
        }
        public override SQLiteErrorCode Rename(SQLiteVirtualTable table, string newName)
        {
            this.CheckDisposed();
            if (table.Rename(newName))
            {
                return(SQLiteErrorCode.Ok);
            }
            CultureInfo currentCulture = CultureInfo.CurrentCulture;

            object[] tableName = new object[] { table.TableName, newName };
            this.SetTableError(table, HelperMethods.StringFormat(currentCulture, "failed to rename virtual table from \"{0}\" to \"{1}\"", tableName));
            return(SQLiteErrorCode.Error);
        }
예제 #15
0
        static SQLiteFactory()
        {
            SQLiteFactory.Instance            = new SQLiteFactory();
            SQLiteFactory.DefaultTypeName     = "EntityWorker.SQLite.Linq.SQLiteProviderServices, EntityWorker.SQLite.Linq, Version={0}, Culture=neutral, PublicKeyToken=db937bc2d44ff139";
            SQLiteFactory.DefaultBindingFlags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic;
            EntityWorker.SQLite.UnsafeNativeMethods.Initialize();
            SQLiteLog.Initialize();
            string      str = "3.5.0.0";
            CultureInfo invariantCulture = CultureInfo.InvariantCulture;

            object[] objArray = new object[] { str };
            SQLiteFactory._dbProviderServicesType = Type.GetType(HelperMethods.StringFormat(invariantCulture, "System.Data.Common.DbProviderServices, System.Data.Entity, Version={0}, Culture=neutral, PublicKeyToken=b77a5c561934e089", objArray), false);
        }
        public override SQLiteErrorCode BestIndex(SQLiteVirtualTable table, SQLiteIndex index)
        {
            this.CheckDisposed();
            if (table.BestIndex(index))
            {
                return(SQLiteErrorCode.Ok);
            }
            CultureInfo currentCulture = CultureInfo.CurrentCulture;

            object[] tableName = new object[] { table.TableName };
            this.SetTableError(table, HelperMethods.StringFormat(currentCulture, "failed to select best index for virtual table \"{0}\"", tableName));
            return(SQLiteErrorCode.Error);
        }
 protected virtual SQLiteErrorCode CursorTypeMismatchError(SQLiteVirtualTableCursor cursor, Type type)
 {
     if (type == null)
     {
         this.SetCursorError(cursor, "cursor type mismatch");
     }
     else
     {
         CultureInfo currentCulture = CultureInfo.CurrentCulture;
         object[]    objArray       = new object[] { type };
         this.SetCursorError(cursor, HelperMethods.StringFormat(currentCulture, "not a \"{0}\" cursor", objArray));
     }
     return(SQLiteErrorCode.Error);
 }
예제 #18
0
 internal static void MaybeBreakIntoDebugger()
 {
     lock (HelperMethods.staticSyncRoot)
     {
         if (HelperMethods.debuggerBreak.HasValue)
         {
             return;
         }
     }
     if (UnsafeNativeMethods.GetSettingValue("PreLoadSQLite_BreakIntoDebugger", null) != null)
     {
         try
         {
             CultureInfo currentCulture = CultureInfo.CurrentCulture;
             object[]    processId      = new object[] { HelperMethods.GetProcessId() };
             Console.WriteLine(HelperMethods.StringFormat(currentCulture, "Attach a debugger to process {0} and press any key to continue.", processId));
             Console.ReadKey();
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             try
             {
                 CultureInfo cultureInfo = CultureInfo.CurrentCulture;
                 object[]    objArray    = new object[] { typeof(Console), exception };
                 Trace.WriteLine(HelperMethods.StringFormat(cultureInfo, "Failed to issue debugger prompt, {0} may be unusable: {1}", objArray));
             }
             catch
             {
             }
         }
         try
         {
             Debugger.Break();
             lock (HelperMethods.staticSyncRoot)
             {
                 HelperMethods.debuggerBreak = new bool?(true);
             }
         }
         catch
         {
             lock (HelperMethods.staticSyncRoot)
             {
                 HelperMethods.debuggerBreak = new bool?(false);
             }
             throw;
         }
     }
 }
예제 #19
0
        public override object Final(object contextData)
        {
            if (this.callback2 == null)
            {
                CultureInfo currentCulture = CultureInfo.CurrentCulture;
                object[]    objArray       = new object[] { "Final" };
                throw new InvalidOperationException(HelperMethods.StringFormat(currentCulture, "No \"{0}\" callback is set.", objArray));
            }
            SQLiteFinalDelegate sQLiteFinalDelegate = this.callback2 as SQLiteFinalDelegate;

            if (sQLiteFinalDelegate != null)
            {
                return(sQLiteFinalDelegate("Final", contextData));
            }
            return(this.callback1.DynamicInvoke(this.GetFinalArgs(contextData, false)));
        }
예제 #20
0
        public override object Invoke(object[] args)
        {
            if (this.callback1 == null)
            {
                CultureInfo currentCulture = CultureInfo.CurrentCulture;
                object[]    objArray       = new object[] { "Invoke" };
                throw new InvalidOperationException(HelperMethods.StringFormat(currentCulture, "No \"{0}\" callback is set.", objArray));
            }
            SQLiteInvokeDelegate sQLiteInvokeDelegate = this.callback1 as SQLiteInvokeDelegate;

            if (sQLiteInvokeDelegate != null)
            {
                return(sQLiteInvokeDelegate("Invoke", args));
            }
            return(this.callback1.DynamicInvoke(this.GetInvokeArgs(args, false)));
        }
예제 #21
0
            internal KeyQuery(SQLiteConnection cnn, string database, string table, params string[] columns)
            {
                using (SQLiteCommandBuilder sQLiteCommandBuilder = new SQLiteCommandBuilder())
                {
                    this._command = cnn.CreateCommand();
                    for (int i = 0; i < (int)columns.Length; i++)
                    {
                        columns[i] = sQLiteCommandBuilder.QuoteIdentifier(columns[i]);
                    }
                }
                SQLiteCommand sQLiteCommand    = this._command;
                CultureInfo   invariantCulture = CultureInfo.InvariantCulture;

                object[] objArray = new object[] { string.Join(",", columns), database, table };
                sQLiteCommand.CommandText = HelperMethods.StringFormat(invariantCulture, "SELECT {0} FROM [{1}].[{2}] WHERE ROWID = ?", objArray);
                this._command.Parameters.AddWithValue(null, (long)0);
            }
예제 #22
0
 internal void FinalCallback(IntPtr context)
 {
     SQLiteFunction.AggregateData aggregateDatum;
     try
     {
         object obj = null;
         if (this._base != null)
         {
             IntPtr intPtr = this._base.AggregateContext(context);
             if (this._contextDataList != null && this._contextDataList.TryGetValue(intPtr, out aggregateDatum))
             {
                 obj = aggregateDatum._data;
                 this._contextDataList.Remove(intPtr);
             }
         }
         try
         {
             this._context = context;
             this.SetReturnValue(context, this.Final(obj));
         }
         finally
         {
             IDisposable disposable = obj as IDisposable;
             if (disposable != null)
             {
                 disposable.Dispose();
             }
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         try
         {
             if (HelperMethods.LogCallbackExceptions(this._flags))
             {
                 CultureInfo currentCulture = CultureInfo.CurrentCulture;
                 object[]    objArray       = new object[] { "Final", exception };
                 SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(currentCulture, "Caught exception in \"{0}\" method: {1}", objArray));
             }
         }
         catch
         {
         }
     }
 }
예제 #23
0
        private SQLiteErrorCode Input(IntPtr context, IntPtr pData, ref int nData)
        {
            SQLiteErrorCode sQLiteErrorCode;

            try
            {
                Stream stream = this.stream;
                if (stream != null)
                {
                    if (nData > 0)
                    {
                        byte[] numArray = new byte[nData];
                        int    num      = stream.Read(numArray, 0, nData);
                        if (num > 0 && pData != IntPtr.Zero)
                        {
                            Marshal.Copy(numArray, 0, pData, num);
                        }
                        nData = num;
                    }
                    sQLiteErrorCode = SQLiteErrorCode.Ok;
                }
                else
                {
                    sQLiteErrorCode = SQLiteErrorCode.Misuse;
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                try
                {
                    if (HelperMethods.LogCallbackExceptions(this.GetFlags()))
                    {
                        CultureInfo currentCulture = CultureInfo.CurrentCulture;
                        object[]    objArray       = new object[] { "xSessionInput", exception };
                        SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(currentCulture, "Caught exception in \"{0}\" method: {1}", objArray));
                    }
                }
                catch
                {
                }
                return(SQLiteErrorCode.IoErr_Read);
            }
            return(sQLiteErrorCode);
        }
예제 #24
0
 internal void StepCallback(IntPtr context, int nArgs, IntPtr argsptr)
 {
     try
     {
         SQLiteFunction.AggregateData aggregateDatum = null;
         if (this._base != null)
         {
             IntPtr intPtr = this._base.AggregateContext(context);
             if (this._contextDataList != null && !this._contextDataList.TryGetValue(intPtr, out aggregateDatum))
             {
                 aggregateDatum = new SQLiteFunction.AggregateData();
                 this._contextDataList[intPtr] = aggregateDatum;
             }
         }
         if (aggregateDatum == null)
         {
             aggregateDatum = new SQLiteFunction.AggregateData();
         }
         try
         {
             this._context = context;
             this.Step(this.ConvertParams(nArgs, argsptr), aggregateDatum._count, ref aggregateDatum._data);
         }
         finally
         {
             aggregateDatum._count++;
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         try
         {
             if (HelperMethods.LogCallbackExceptions(this._flags))
             {
                 CultureInfo currentCulture = CultureInfo.CurrentCulture;
                 object[]    objArray       = new object[] { "Step", exception };
                 SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(currentCulture, "Caught exception in \"{0}\" method: {1}", objArray));
             }
         }
         catch
         {
         }
     }
 }
예제 #25
0
        public void LoadDifferencesFromTable(string fromDatabaseName, string tableName)
        {
            this.CheckDisposed();
            this.CheckHandle();
            if (fromDatabaseName == null)
            {
                throw new ArgumentNullException("fromDatabaseName");
            }
            if (tableName == null)
            {
                throw new ArgumentNullException("tableName");
            }
            IntPtr zero = IntPtr.Zero;

            try
            {
                SQLiteErrorCode sQLiteErrorCode = UnsafeNativeMethods.sqlite3session_diff(this.session, SQLiteString.GetUtf8BytesFromString(fromDatabaseName), SQLiteString.GetUtf8BytesFromString(tableName), ref zero);
                if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                {
                    string str = null;
                    if (zero != IntPtr.Zero)
                    {
                        str = SQLiteString.StringFromUtf8IntPtr(zero);
                        if (!string.IsNullOrEmpty(str))
                        {
                            CultureInfo currentCulture = CultureInfo.CurrentCulture;
                            object[]    objArray       = new object[] { str };
                            str = HelperMethods.StringFormat(currentCulture, ": {0}", objArray);
                        }
                    }
                    CultureInfo cultureInfo = CultureInfo.CurrentCulture;
                    object[]    objArray1   = new object[] { "sqlite3session_diff", str };
                    throw new SQLiteException(sQLiteErrorCode, HelperMethods.StringFormat(cultureInfo, "{0}{1}", objArray1));
                }
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    SQLiteMemory.Free(zero);
                    zero = IntPtr.Zero;
                }
            }
        }
예제 #26
0
        public override void Step(object[] args, int stepNumber, ref object contextData)
        {
            if (this.callback1 == null)
            {
                CultureInfo currentCulture = CultureInfo.CurrentCulture;
                object[]    objArray       = new object[] { "Step" };
                throw new InvalidOperationException(HelperMethods.StringFormat(currentCulture, "No \"{0}\" callback is set.", objArray));
            }
            SQLiteStepDelegate sQLiteStepDelegate = this.callback1 as SQLiteStepDelegate;

            if (sQLiteStepDelegate != null)
            {
                sQLiteStepDelegate("Step", args, stepNumber, ref contextData);
                return;
            }
            object[] stepArgs = this.GetStepArgs(args, stepNumber, contextData, false);
            this.callback1.DynamicInvoke(stepArgs);
            this.UpdateStepArgs(stepArgs, ref contextData, false);
        }
예제 #27
0
        public static string ToDisplayString(object value)
        {
            if (value == null)
            {
                return("<nullObject>");
            }
            string str = value.ToString();

            if (str.Length == 0)
            {
                return("<emptyString>");
            }
            if (str.IndexOfAny(HelperMethods.SpaceChars) < 0)
            {
                return(str);
            }
            CultureInfo invariantCulture = CultureInfo.InvariantCulture;

            object[] objArray = new object[] { str };
            return(HelperMethods.StringFormat(invariantCulture, "\"{0}\"", objArray));
        }
예제 #28
0
 internal void ScalarCallback(IntPtr context, int nArgs, IntPtr argsptr)
 {
     try
     {
         this._context = context;
         this.SetReturnValue(context, this.Invoke(this.ConvertParams(nArgs, argsptr)));
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         try
         {
             if (HelperMethods.LogCallbackExceptions(this._flags))
             {
                 CultureInfo currentCulture = CultureInfo.CurrentCulture;
                 object[]    objArray       = new object[] { "Invoke", exception };
                 SQLiteLog.LogMessage(-2146233088, HelperMethods.StringFormat(currentCulture, "Caught exception in \"{0}\" method: {1}", objArray));
             }
         }
         catch
         {
         }
     }
 }
예제 #29
0
        public override int Compare(string param1, string param2)
        {
            if (this.callback1 == null)
            {
                CultureInfo currentCulture = CultureInfo.CurrentCulture;
                object[]    objArray       = new object[] { "Compare" };
                throw new InvalidOperationException(HelperMethods.StringFormat(currentCulture, "No \"{0}\" callback is set.", objArray));
            }
            SQLiteCompareDelegate sQLiteCompareDelegate = this.callback1 as SQLiteCompareDelegate;

            if (sQLiteCompareDelegate != null)
            {
                return(sQLiteCompareDelegate("Compare", param1, param2));
            }
            object obj = this.callback1.DynamicInvoke(this.GetCompareArgs(param1, param2, false));

            if (!(obj is int))
            {
                CultureInfo cultureInfo = CultureInfo.CurrentCulture;
                object[]    objArray1   = new object[] { "Compare" };
                throw new InvalidOperationException(HelperMethods.StringFormat(cultureInfo, "\"{0}\" result must be Int32.", objArray1));
            }
            return((int)obj);
        }
예제 #30
0
        internal override void Open(string strFilename, string vfsName, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, int maxPoolSize, bool usePool)
        {
            SQLiteErrorCode sQLiteErrorCode;

            if (this._sql != null)
            {
                this.Close(true);
            }
            if (this._sql != null)
            {
                throw new SQLiteException("connection handle is still active");
            }
            this._usePool  = usePool;
            this._fileName = strFilename;
            this._flags    = connectionFlags;
            if (usePool)
            {
                this._sql = SQLiteConnectionPool.Remove(strFilename, maxPoolSize, out this._poolVersion);
                SQLiteConnectionHandle sQLiteConnectionHandle = this._sql;
                object[] objArray = new object[] { typeof(SQLite3_UTF16), strFilename, vfsName, connectionFlags, openFlags, maxPoolSize, usePool, this._poolVersion };
                SQLiteConnection.OnChanged(null, new ConnectionEventArgs(SQLiteConnectionEventType.OpenedFromPool, null, null, null, null, sQLiteConnectionHandle, strFilename, objArray));
            }
            if (this._sql == null)
            {
                try
                {
                }
                finally
                {
                    IntPtr zero = IntPtr.Zero;
                    int    num  = ((connectionFlags & SQLiteConnectionFlags.NoExtensionFunctions) != SQLiteConnectionFlags.NoExtensionFunctions ? 1 : 0);
                    if (vfsName != null || num != 0)
                    {
                        sQLiteErrorCode = UnsafeNativeMethods.sqlite3_open16_interop(SQLiteConvert.ToUTF8(strFilename), SQLiteConvert.ToUTF8(vfsName), openFlags, num, ref zero);
                    }
                    else
                    {
                        if ((openFlags & SQLiteOpenFlagsEnum.Create) != SQLiteOpenFlagsEnum.Create && !File.Exists(strFilename))
                        {
                            throw new SQLiteException(SQLiteErrorCode.CantOpen, strFilename);
                        }
                        if (vfsName != null)
                        {
                            CultureInfo currentCulture = CultureInfo.CurrentCulture;
                            object[]    objArray1      = new object[] { vfsName };
                            throw new SQLiteException(SQLiteErrorCode.CantOpen, HelperMethods.StringFormat(currentCulture, "cannot open using UTF-16 and VFS \"{0}\": need interop assembly", objArray1));
                        }
                        sQLiteErrorCode = UnsafeNativeMethods.sqlite3_open16(strFilename, ref zero);
                    }
                    if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                    {
                        throw new SQLiteException(sQLiteErrorCode, null);
                    }
                    this._sql = new SQLiteConnectionHandle(zero, true);
                }
                lock (this._sql)
                {
                }
                SQLiteConnectionHandle sQLiteConnectionHandle1 = this._sql;
                object[] objArray2 = new object[] { typeof(SQLite3_UTF16), strFilename, vfsName, connectionFlags, openFlags, maxPoolSize, usePool };
                SQLiteConnection.OnChanged(null, new ConnectionEventArgs(SQLiteConnectionEventType.NewCriticalHandle, null, null, null, null, sQLiteConnectionHandle1, strFilename, objArray2));
            }
            if ((connectionFlags & SQLiteConnectionFlags.NoBindFunctions) != SQLiteConnectionFlags.NoBindFunctions)
            {
                if (this._functions == null)
                {
                    this._functions = new Dictionary <SQLiteFunctionAttribute, SQLiteFunction>();
                }
                foreach (KeyValuePair <SQLiteFunctionAttribute, SQLiteFunction> value in SQLiteFunction.BindFunctions(this, connectionFlags))
                {
                    this._functions[value.Key] = value.Value;
                }
            }
            this.SetTimeout(0);
            GC.KeepAlive(this._sql);
        }