public SQLite3Provider() { #if WINDOWS_PHONE IntPtr db; int rc; ISQLite3Provider me = this as ISQLite3Provider; rc = me.sqlite3_open(":memory:", out db); if (0 == rc) { string errmsg; rc = me.sqlite3_exec(db, string.Format("PRAGMA temp_store_directory = '{0}';", Windows.Storage.ApplicationData.Current.LocalFolder.Path), null, null, out errmsg); // ignore rc, I guess rc = me.sqlite3_exec(db, string.Format("PRAGMA data_store_directory = '{0}';", Windows.Storage.ApplicationData.Current.LocalFolder.Path), null, null, out errmsg); // ignore rc, I guess rc = me.sqlite3_close(db); // ignore rc, I guess } #elif NETFX_CORE IntPtr db; int rc; ISQLite3Provider me = this as ISQLite3Provider; rc = me.sqlite3_open(":memory:", out db); if (0 == rc) { string errmsg; rc = me.sqlite3_exec(db, string.Format("PRAGMA temp_store_directory = '{0}';", Windows.Storage.ApplicationData.Current.TemporaryFolder.Path), null, null, out errmsg); // ignore rc, I guess rc = me.sqlite3_exec(db, string.Format("PRAGMA data_store_directory = '{0}';", Windows.Storage.ApplicationData.Current.LocalFolder.Path), null, null, out errmsg); // ignore rc, I guess rc = me.sqlite3_close(db); // ignore rc, I guess } #endif }
static public void SetProvider(ISQLite3Provider imp) { int version = imp.sqlite3_libversion_number(); IntPtr db; int rc; rc = imp.sqlite3_open(":memory:", out db); if (rc != 0) { throw new Exception(); } rc = imp.sqlite3_close(db); if (rc != 0) { throw new Exception(); } _imp = imp; }
internal SQLiteStatement(SQLiteConnection connection, IntPtr stm) { this.platformMarshal = Platform.Instance.PlatformMarshal; this.sqlite3Provider = Platform.Instance.SQLite3Provider; this.connection = connection; this.stm = stm; this.columnNameIndexDic = new Dictionary<string, int>(); this.columnIndexNameDic = new Dictionary<int, string>(); for (int index = 0; index < this.ColumnCount; index++) { var name = this.platformMarshal.MarshalStringNativeUTF8ToManaged(this.sqlite3Provider.Sqlite3ColumnName(this.stm, index)); // Will only track the first appearence of a particular column name if (!string.IsNullOrEmpty(name) && !this.columnNameIndexDic.ContainsKey(name)) { this.columnNameIndexDic.Add(name, index); } this.columnIndexNameDic.Add(index, name); } }
static public void SetProvider(ISQLite3Provider imp) { if (_frozen) { return; } int version = imp.sqlite3_libversion_number(); #if not // don't do this, because it ends up calling sqlite3_initialize IntPtr db; int rc; rc = imp.sqlite3_open(":memory:", out db); if (rc != 0) { throw new Exception(); } rc = imp.sqlite3_close(db); if (rc != 0) { throw new Exception(); } #endif _imp = imp; }
internal SQLiteStatement(SQLiteConnection connection, IntPtr stm) { this.platformMarshal = Platform.Instance.PlatformMarshal; this.sqlite3Provider = Platform.Instance.SQLite3Provider; this.connection = connection; this.stm = stm; this.columnNameIndexDic = new Dictionary <string, int>(); this.columnIndexNameDic = new Dictionary <int, string>(); for (int index = 0; index < this.ColumnCount; index++) { var name = this.platformMarshal.MarshalStringNativeUTF8ToManaged(this.sqlite3Provider.Sqlite3ColumnName(this.stm, index)); // Will only track the first appearence of a particular column name if (!string.IsNullOrEmpty(name) && !this.columnNameIndexDic.ContainsKey(name)) { this.columnNameIndexDic.Add(name, index); } this.columnIndexNameDic.Add(index, name); } }
private SQLiteConnection(string fileName, SQLiteOpen openFlag, bool setTemporaryDirectory) { this.platformMarshal = Platform.Instance.PlatformMarshal; this.platformStorage = Platform.Instance.PlatformStorage; this.sqlite3Provider = Platform.Instance.SQLite3Provider; if (setTemporaryDirectory) { this.SetTemporaryDirectory(); } var localFilePath = string.Empty; if (fileName.Trim().ToLowerInvariant() == ":memory:") { localFilePath = ":memory:"; } else if (fileName.Trim() != string.Empty) { localFilePath = this.platformStorage.GetLocalFilePath(fileName); } var fileNamePtr = this.platformMarshal.MarshalStringManagedToNativeUTF8(localFilePath); int flags; switch (openFlag) { case SQLiteOpen.READONLY: // URI|DONTCREATE|READONLY flags = 0x41; break; case SQLiteOpen.READWRITE: // URI|CREATE|READWRITE flags = 0x46; break; default: // URI|CREATE|READWRITE flags = 0x46; break; } try { var openResult = (SQLiteResult)this.sqlite3Provider.Sqlite3Open(fileNamePtr, out this.db, flags); if (openResult != SQLiteResult.OK) { if (this.db != IntPtr.Zero) { var errmsgPtr = this.sqlite3Provider.Sqlite3Errmsg(this.db); var errmsg = this.platformMarshal.MarshalStringNativeUTF8ToManaged(errmsgPtr); this.sqlite3Provider.Sqlite3CloseV2(this.db); throw new SQLiteException("Unable to open the database file: " + fileName + " Details: " + errmsg); } else { throw new SQLiteException("Unable to open the database file: " + fileName + " Details: " + openResult.ToString()); } } } catch (SQLiteException) { throw; } catch (Exception ex) { throw new SQLiteException("Unable to open the database file: " + fileName, ex); } finally { if (fileNamePtr != IntPtr.Zero) { this.platformMarshal.CleanUpStringNativeUTF8(fileNamePtr); } } }
static raw() { _imp = new SQLite3Provider_bait(); _frozen = false; }
static raw() { _imp = new SQLite3Provider_bait(); }