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); } }
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); } } }