public static int sqlite3_prepare_v2( DatabaseHandle db, string zSql, out StatementHandle ppStmt, out string pzTail) { int nByte; var zSqlPtr = MarshalEx.StringToHGlobalUTF8(zSql, out nByte); try { IntPtr pzTailPtr; var rc = sqlite3_prepare_v2(db, zSqlPtr, nByte, out ppStmt, out pzTailPtr); pzTail = MarshalEx.PtrToStringUTF8(pzTailPtr); return(rc); } finally { if (zSqlPtr != IntPtr.Zero) { Marshal.FreeHGlobal(zSqlPtr); } } }
public void StringToHGlobalUTF8_returns_zero_when_null() { int size; var ptr = MarshalEx.StringToHGlobalUTF8(null, out size); Assert.Equal(IntPtr.Zero, ptr); Assert.Equal(0, size); }
public static int sqlite3_bind_parameter_index(StatementHandle pStmt, string zName) { var ptr = MarshalEx.StringToHGlobalUTF8(zName); try { return(sqlite3_bind_parameter_index(pStmt, ptr)); } finally { if (ptr != IntPtr.Zero) { Marshal.FreeHGlobal(ptr); } } }
public static string sqlite3_db_filename(DatabaseHandle db, string zDbName) { var ptr = MarshalEx.StringToHGlobalUTF8(zDbName); try { return(MarshalEx.PtrToStringUTF8(sqlite3_db_filename(db, ptr))); } finally { if (ptr != IntPtr.Zero) { Marshal.FreeHGlobal(ptr); } } }
public static int sqlite3_bind_text(StatementHandle pStmt, int i, string zData) { int size; var ptr = MarshalEx.StringToHGlobalUTF8(zData, out size); try { return(sqlite3_bind_text(pStmt, i, ptr, size - 1, Constants.SQLITE_TRANSIENT)); } finally { if (ptr != IntPtr.Zero) { Marshal.FreeHGlobal(ptr); } } }
public void StringToHGlobalUTF8_and_PtrToStringUTF8_roundtrip() { var s = "text"; int size; var ptr = MarshalEx.StringToHGlobalUTF8(s, out size); try { var result = MarshalEx.PtrToStringUTF8(ptr); Assert.Equal(s, result); } finally { Marshal.FreeHGlobal(ptr); } }
public static int sqlite3_open_v2(string filename, out DatabaseHandle ppDb, int flags, string zVfs) { var filenamePtr = MarshalEx.StringToHGlobalUTF8(filename); var zVfsPtr = MarshalEx.StringToHGlobalUTF8(zVfs); try { return(sqlite3_open_v2(filenamePtr, out ppDb, flags, zVfsPtr)); } finally { if (filenamePtr != IntPtr.Zero) { Marshal.FreeHGlobal(filenamePtr); } if (zVfsPtr != IntPtr.Zero) { Marshal.FreeHGlobal(zVfsPtr); } } }