public override void viewDidLoad() { base.viewDidLoad(); if (splitViewController != null) { detailViewController = (DetailViewController)(splitViewController.viewControllers().lastObject().topViewController); } _objects = new NSMutableArray(); string lDatabaseName = NSBundle.mainBundle.pathForResource("PCTrade.sqlite") ofType("db"); NSLog("%@", lDatabaseName); sqlite3 *lDatabase = null; if (sqlite3_open(lDatabaseName.cStringUsingEncoding(NSStringEncoding.NSUTF8StringEncoding), &lDatabase) == SQLITE_OK) { sqlite3_stmt *lStatement; if (sqlite3_prepare_v2(lDatabase, "select * from Customers", -1, &lStatement, null) == SQLITE_OK) { while (sqlite3_step(lStatement) == SQLITE_ROW) { var lName = (AnsiChar *)(sqlite3_column_text(lStatement, 1)); _objects.addObject(NSString.stringWithUTF8String(lName)); NSLog("row: %s", lName); } } sqlite3_close(lDatabase); } tableView.reloadData(); }
/* ** This function is a complex assert() that verifies the following ** properties of the blocked connections list: ** ** 1) Each entry in the list has a non-NULL value for either ** pUnlockConnection or pBlockingConnection, or both. ** ** 2) All entries in the list that share a common value for ** xUnlockNotify are grouped together. ** ** 3) If the argument db is not NULL, then none of the entries in the ** blocked connections list have pUnlockConnection or pBlockingConnection ** set to db. This is used when closing connection db. */ static void checkListProperties(sqlite3 *db) { sqlite3 *p; for (p = sqlite3BlockedList; p; p = p->pNextBlocked) { int seen = 0; sqlite3 *p2; /* Verify property (1) */ assert(p->pUnlockConnection || p->pBlockingConnection); /* Verify property (2) */ for (p2 = sqlite3BlockedList; p2 != p; p2 = p2->pNextBlocked) { if (p2->xUnlockNotify == p->xUnlockNotify) { seen = 1; } assert(p2->xUnlockNotify == p->xUnlockNotify || !seen); assert(db == 0 || p->pUnlockConnection != db); assert(db == 0 || p->pBlockingConnection != db); } } }
internal static extern int sqlite3_prepare_v2( sqlite3 *db, /* Database handle */ string zSql, /* SQL statement, UTF-8 encoded */ int nByte, /* Maximum length of zSql in bytes. */ out sqlite3_stmt *ppStmt, /* OUT: Statement handle */ out char *pzTail /* OUT: Pointer to unused portion of zSql */ );
internal static extern int sqlite3_exec( sqlite3 *db, /* An open database */ string sql, /* SQL to be evaluated */ IntPtr callback, /* Callback function */ IntPtr firstArg, /* 1st argument to callback */ IntPtr errmsg /* Error msg written here */ );
private static bool CreateTable(sqlite3* db, string sql) { sqlite3_stmt* createTableStmt; char* tail; int error = NativeMethods.sqlite3_prepare_v2(db, sql, sql.Length, out createTableStmt, out tail); if (error != 0) { LogErrorWithTimeStamp("sqlite3_prepare_v2 -> " + sql + " failed to execute with SQLite error code: " + error); NativeMethods.sqlite3_finalize(createTableStmt); return false; } error = NativeMethods.sqlite3_step(createTableStmt); if (error != 101) { LogErrorWithTimeStamp("sqlite3_step -> " + sql + " failed to execute with SQLite error code: " + error); NativeMethods.sqlite3_finalize(createTableStmt); return false; } NativeMethods.sqlite3_finalize(createTableStmt); return true; }
private static bool CreateTables(sqlite3* db) { if (!CreateTable(db, @"CREATE TABLE Objects(ObjectId INTEGER PRIMARY KEY, TypeId INTEGER, Size INTEGER);")) { return false; } if (!CreateTable(db, @"CREATE TABLE ObjectReferences(ObjectId INTEGER PRIMARY KEY, ObjectReference INTEGER);")) { return false; } if (!CreateTable(db, @"CREATE INDEX `ObjRefIndex` ON `ObjectReferences` (`ObjectReference` ASC);")) { return false; } if (!CreateTable(db, @"CREATE TABLE Types(TypeId INTEGER PRIMARY KEY, Count INTEGER, Size INTEGER, Name TEXT);")) { return false; } if (!CreateTable(db, "CREATE TABLE Roots(TypeId INTEGER, ObjectId INTEGER, Address INTEGER, AppDomainId INTEGER, ManagedThreadId INTEGER, IsInterior BOOLEAN, IsPinned BOOLEAN, IsPossibleFalsePositive BOOLEAN, GCRootKind TEXT, Name TEXT);")) { return false; } if (!CreateTable(db, "CREATE TABLE BlockingObjects(ObjectId INTEGER, Taken BOOLEAN, RecursionCount INTEGER, Owner INTEGER, HasSingleOwner BOOL, ThreadOwnerIds TEXT, ThreadWaiterIds TEXT, BlockingReason TEXT);")) { return false; } return true; }
/* ** Open a blob handle. */ int sqlite3_blob_open( sqlite3 *db, /* The database connection */ string zDb, /* The attached database containing the blob */ string zTable, /* The table containing the blob */ string zColumn, /* The column containing the blob */ sqlite_int64 iRow, /* The row containing the glob */ int flags, /* True -> read/write access, false -> read-only */ sqlite3_blob **ppBlob /* Handle for accessing the blob returned here */ ) { int nAttempt = 0; int iCol; /* Index of zColumn in row-record */
private static bool PrepareInsertStatement(sqlite3* db, out sqlite3_stmt* stmt, string sql) { char* tail; int error = NativeMethods.sqlite3_prepare_v2(db, sql, sql.Length, out stmt, out tail); if (error != 0) { LogErrorWithTimeStamp("sqlite3_prepare_v2 -> " + sql + " failed to execute with SQLite error code: " + error); return false; } return true; }
void sqlite3BtreeEnterAll(sqlite3 *db) { int i; for (i = 0; i < db->nDb; i++) { Btree *p = db->aDb[i].pBt; if (p) { p->pBt->db = p->db; } } }
//# define checkListProperties(x) #endif /* ** Remove connection db from the blocked connections list. If connection ** db is not currently a part of the list, this function is a no-op. */ static void removeFromBlockedList(sqlite3 *db) { sqlite3 **pp; assertMutexHeld(); for (pp = &sqlite3BlockedList; *pp; pp = &(*pp)->pNextBlocked) { if (*pp == db) { *pp = (*pp)->pNextBlocked; break; } } }
void sqlite3BtreeLeaveAll(sqlite3 *db) { int i; Btree *p; assert(sqlite3_mutex_held(db->mutex)); for (i = 0; i < db->nDb; i++) { p = db->aDb[i].pBt; if (p) { sqlite3BtreeLeave(p); } } }
/* ** Add connection db to the blocked connections list. It is assumed ** that it is not already a part of the list. */ static void addToBlockedList(sqlite3 *db) { sqlite3 **pp; assertMutexHeld(); for ( pp = &sqlite3BlockedList; *pp && (*pp)->xUnlockNotify != db->xUnlockNotify; pp = &(*pp)->pNextBlocked ) { ; } db->pNextBlocked = *pp; *pp = db; }
/* ** Enter the mutex on every Btree associated with a database ** connection. This is needed (for example) prior to parsing ** a statement since we will be comparing table and column names ** against all schemas and we do not want those schemas being ** reset out from under us. ** ** There is a corresponding leave-all procedures. ** ** Enter the mutexes in accending order by BtShared pointer address ** to avoid the possibility of deadlock when two threads with ** two or more btrees in common both try to lock all their btrees ** at the same instant. */ void sqlite3BtreeEnterAll(sqlite3 *db) { int i; Btree *p, *pLater; assert(sqlite3_mutex_held(db->mutex)); for (i = 0; i < db->nDb; i++) { p = db->aDb[i].pBt; assert(!p || (p->locked == 0 && p->sharable) || p->pBt->db == p->db); if (p && p->sharable) { p->wantToLock++; if (!p->locked) { assert(p->wantToLock == 1); while (p->pPrev) { p = p->pPrev; } /* Reason for ALWAYS: There must be at least on unlocked Btree in ** the chain. Otherwise the !p->locked test above would have failed */ while (p->locked && ALWAYS(p->pNext)) { p = p->pNext; } for (pLater = p->pNext; pLater; pLater = pLater->pNext) { if (pLater->locked) { unlockBtreeMutex(pLater); } } while (p) { lockBtreeMutex(p); p = p->pNext; } } } } }
void sqlite3BtreeLeaveAll(sqlite3 *db) { int i; Btree *p; assert(sqlite3_mutex_held(db->mutex)); for (i = 0; i < db->nDb; i++) { p = db->aDb[i].pBt; if (p && p->sharable) { assert(p->wantToLock > 0); p->wantToLock--; if (p->wantToLock == 0) { unlockBtreeMutex(p); } } } }
/* ** Return true if the current thread holds the database connection ** mutex and all required BtShared mutexes. ** ** This routine is used inside assert() statements only. */ int sqlite3BtreeHoldsAllMutexes(sqlite3 *db) { int i; if (!sqlite3_mutex_held(db->mutex)) { return(0); } for (i = 0; i < db->nDb; i++) { Btree *p; p = db->aDb[i].pBt; if (p && p->sharable && (p->wantToLock == 0 || !sqlite3_mutex_held(p->pBt->mutex))) { return(0); } } return(1); }
/* ** Return true if the correct mutexes are held for accessing the ** db->aDb[iDb].pSchema structure. The mutexes required for schema ** access are: ** ** (1) The mutex on db ** (2) if iDb!=1, then the mutex on db->aDb[iDb].pBt. ** ** If pSchema is not NULL, then iDb is computed from pSchema and ** db using sqlite3SchemaToIndex(). */ int sqlite3SchemaMutexHeld(sqlite3 *db, int iDb, Schema *pSchema) { Btree *p; assert(db != 0); if (pSchema) { iDb = sqlite3SchemaToIndex(db, pSchema); } assert(iDb >= 0 && iDb < db->nDb); if (!sqlite3_mutex_held(db->mutex)) { return(0); } if (iDb == 1) { return(1); } p = db->aDb[iDb].pBt; assert(p != 0); return(p->sharable == 0 || p->locked == 1); }
/* ** TRUE if p is a lookaside memory allocation from db */ #if !SQLITE_OMIT_LOOKASIDE static int isLookaside(sqlite3 *db, void *p){ return db && p && p>=db->lookaside.pStart && p<db->lookaside.pEnd; }
internal static extern int sqlite3_open(string filename, out sqlite3 *ppDb);
internal static extern int sqlite3_close(sqlite3 *db);
/* ** Open a blob handle. */ int sqlite3_blob_open( sqlite3 *db, /* The database connection */
/* ** Extension load function. */ int sqlite3_extension_init( sqlite3 *db, char **pzErrMsg,
/* ** 2003 January 11 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains code used to implement the sqlite3_set_authorizer() ** API. This facility is an optional feature of the library. Embedded ** systems that do not need this facility may omit it by recompiling ** the library with -DSQLITE_OMIT_AUTHORIZATION=1 ************************************************************************* ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart ** C#-SQLite is an independent reimplementation of the SQLite software library ** ** SQLITE_SOURCE_ID: 2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3 ** ************************************************************************* */ //#include "sqliteInt.h" /* ** All of the code in this file may be omitted by defining a single ** macro. */ #if !SQLITE_OMIT_AUTHORIZATION /* ** Set or clear the access authorization function. ** ** The access authorization function is be called during the compilation ** phase to verify that the user has read and/or write access permission on ** various fields of the database. The first argument to the auth function ** is a copy of the 3rd argument to this routine. The second argument ** to the auth function is one of these constants: ** ** SQLITE_CREATE_INDEX ** SQLITE_CREATE_TABLE ** SQLITE_CREATE_TEMP_INDEX ** SQLITE_CREATE_TEMP_TABLE ** SQLITE_CREATE_TEMP_TRIGGER ** SQLITE_CREATE_TEMP_VIEW ** SQLITE_CREATE_TRIGGER ** SQLITE_CREATE_VIEW ** SQLITE_DELETE ** SQLITE_DROP_INDEX ** SQLITE_DROP_TABLE ** SQLITE_DROP_TEMP_INDEX ** SQLITE_DROP_TEMP_TABLE ** SQLITE_DROP_TEMP_TRIGGER ** SQLITE_DROP_TEMP_VIEW ** SQLITE_DROP_TRIGGER ** SQLITE_DROP_VIEW ** SQLITE_INSERT ** SQLITE_PRAGMA ** SQLITE_READ ** SQLITE_SELECT ** SQLITE_TRANSACTION ** SQLITE_UPDATE ** ** The third and fourth arguments to the auth function are the name of ** the table and the column that are being accessed. The auth function ** should return either SQLITE_OK, SQLITE_DENY, or SQLITE_IGNORE. If ** SQLITE_OK is returned, it means that access is allowed. SQLITE_DENY ** means that the SQL statement will never-run - the sqlite3_exec() call ** will return with an error. SQLITE_IGNORE means that the SQL statement ** should run but attempts to read the specified column will return NULL ** and attempts to write the column will be ignored. ** ** Setting the auth function to NULL disables this hook. The default ** setting of the auth function is NULL. */ int sqlite3_set_authorizer( sqlite3 *db, int (*xAuth)(void *, int, const char *, const char *, const char *, const char *),
// HOOKS #if SQLITE_ENABLE_UNLOCK_NOTIFY public void sqlite3ConnectionBlocked(sqlite3 *, sqlite3);
/* ** Register an unlock-notify callback. ** ** This is called after connection "db" has attempted some operation ** but has received an SQLITE_LOCKED error because another connection ** (call it pOther) in the same process was busy using the same shared ** cache. pOther is found by looking at db->pBlockingConnection. ** ** If there is no blocking connection, the callback is invoked immediately, ** before this routine returns. ** ** If pOther is already blocked on db, then report SQLITE_LOCKED, to indicate ** a deadlock. ** ** Otherwise, make arrangements to invoke xNotify when pOther drops ** its locks. ** ** Each call to this routine overrides any prior callbacks registered ** on the same "db". If xNotify==0 then any prior callbacks are immediately ** cancelled. */ int sqlite3_unlock_notify( sqlite3 *db, void (*xNotify)(void **, int),
/* ** 2006 June 10 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains code used to help implement virtual tables. ************************************************************************* ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart ** C#-SQLite is an independent reimplementation of the SQLite software library ** ** SQLITE_SOURCE_ID: 2010-12-07 20:14:09 a586a4deeb25330037a49df295b36aaf624d0f45 ** ************************************************************************* */ #if !SQLITE_OMIT_VIRTUALTABLE //#include "sqliteInt.h" /* ** The actual function that does the work of creating a new module. ** This function implements the sqlite3_create_module() and ** sqlite3_create_module_v2() interfaces. */ static int createModule( sqlite3 *db, /* Database in which module is registered */