X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FMono.Data.Sqlite%2FMono.Data.Sqlite_2.0%2FSQLite3.cs;h=6b2ee13e03a86fed9d1c387bf2dbb38b85bdd904;hb=30cddad5fb4c3d290906a6e6c33ecd8b07d8b48c;hp=82a40ed6c8a1efc6c0a95ab55b5e7884ca7e9b94;hpb=e8c79817a3ed67a5924836d757d6d21cc93abda1;p=mono.git diff --git a/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLite3.cs b/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLite3.cs index 82a40ed6c8a..6b2ee13e03a 100644 --- a/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLite3.cs +++ b/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLite3.cs @@ -125,9 +125,9 @@ namespace Mono.Data.Sqlite // Compatibility with versions < 3.5.0 int n; - try { + if (UnsafeNativeMethods.use_sqlite3_open_v2) { n = UnsafeNativeMethods.sqlite3_open_v2(ToUTF8(strFilename), out db, (int)flags, IntPtr.Zero); - } catch (EntryPointNotFoundException) { + } else { Console.WriteLine ("Your sqlite3 version is old - please upgrade to at least v3.5.0!"); n = UnsafeNativeMethods.sqlite3_open (ToUTF8 (strFilename), out db); } @@ -499,6 +499,8 @@ namespace Mono.Data.Sqlite #if !SQLITE_STANDARD int len; return UTF8ToString(UnsafeNativeMethods.sqlite3_column_origin_name_interop(stmt._sqlite_stmt, index, out len), len); +#elif MONOTOUCH + throw new NotImplementedException (); #else return UTF8ToString(UnsafeNativeMethods.sqlite3_column_origin_name(stmt._sqlite_stmt, index), -1); #endif @@ -509,6 +511,8 @@ namespace Mono.Data.Sqlite #if !SQLITE_STANDARD int len; return UTF8ToString(UnsafeNativeMethods.sqlite3_column_database_name_interop(stmt._sqlite_stmt, index, out len), len); +#elif MONOTOUCH + throw new NotImplementedException (); #else return UTF8ToString(UnsafeNativeMethods.sqlite3_column_database_name(stmt._sqlite_stmt, index), -1); #endif @@ -519,6 +523,8 @@ namespace Mono.Data.Sqlite #if !SQLITE_STANDARD int len; return UTF8ToString(UnsafeNativeMethods.sqlite3_column_table_name_interop(stmt._sqlite_stmt, index, out len), len); +#elif MONOTOUCH + throw new NotImplementedException (); #else return UTF8ToString(UnsafeNativeMethods.sqlite3_column_table_name(stmt._sqlite_stmt, index), -1); #endif @@ -652,11 +658,37 @@ namespace Mono.Data.Sqlite return UnsafeNativeMethods.sqlite3_aggregate_count(context); } +#if MONOTOUCH + class FunctionData { + public SQLiteCallback Func; + public SQLiteCallback FuncStep; + public SQLiteFinalCallback FuncFinal; + } +#endif + internal override void CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func, SQLiteCallback funcstep, SQLiteFinalCallback funcfinal) { int n; -#if !SQLITE_STANDARD +#if MONOTOUCH + var data = new FunctionData(); + data.Func = func; + data.FuncStep = funcstep; + data.FuncFinal = funcfinal; + SQLiteCallback func_callback = func == null ? null : new SQLiteCallback(scalar_callback); + SQLiteCallback funcstep_callback = funcstep == null ? null : new SQLiteCallback(step_callback); + SQLiteFinalCallback funcfinal_callback = funcfinal == null ? null : new SQLiteFinalCallback(final_callback); + + IntPtr user_data; + user_data = GCHandle.ToIntPtr(GCHandle.Alloc(data)); + n = UnsafeNativeMethods.sqlite3_create_function_v2(_sql, ToUTF8(strFunction), nArgs, 4, user_data, func_callback, funcstep_callback, funcfinal_callback, destroy_callback); + + if (n == 0) { + // sqlite3_create_function_v2 will call 'destroy_callback' if it fails, so we need to recreate the gchandle here. + user_data = GCHandle.ToIntPtr(GCHandle.Alloc(data)); + n = UnsafeNativeMethods.sqlite3_create_function_v2(_sql, ToUTF8(strFunction), nArgs, 1, user_data, func_callback, funcstep_callback, funcfinal_callback, destroy_callback); + } +#elif !SQLITE_STANDARD n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0); if (n == 0) n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0); #else @@ -666,13 +698,45 @@ namespace Mono.Data.Sqlite if (n > 0) throw new SqliteException(n, SQLiteLastError()); } - internal override void CreateCollation(string strCollation, SQLiteCollation func, SQLiteCollation func16) + internal override void CreateCollation(string strCollation, SQLiteCollation func, SQLiteCollation func16, IntPtr user_data) { - int n = UnsafeNativeMethods.sqlite3_create_collation(_sql, ToUTF8(strCollation), 2, IntPtr.Zero, func16); - if (n == 0) UnsafeNativeMethods.sqlite3_create_collation(_sql, ToUTF8(strCollation), 1, IntPtr.Zero, func); + int n = UnsafeNativeMethods.sqlite3_create_collation(_sql, ToUTF8(strCollation), 2, user_data, func16); + if (n == 0) UnsafeNativeMethods.sqlite3_create_collation(_sql, ToUTF8(strCollation), 1, user_data, func); if (n > 0) throw new SqliteException(n, SQLiteLastError()); } +#if MONOTOUCH + [Mono.Util.MonoPInvokeCallback(typeof(SQLiteCallback))] + internal static void scalar_callback(IntPtr context, int nArgs, IntPtr argsptr) + { + var handle = GCHandle.FromIntPtr (UnsafeNativeMethods.sqlite3_user_data(context)); + var func = (FunctionData)handle.Target; + func.Func(context, nArgs, argsptr); + } + + [Mono.Util.MonoPInvokeCallback(typeof(SQLiteCallback))] + internal static void step_callback(IntPtr context, int nArgs, IntPtr argsptr) + { + var handle = GCHandle.FromIntPtr(UnsafeNativeMethods.sqlite3_user_data(context)); + var func = (FunctionData)handle.Target; + func.FuncStep(context, nArgs, argsptr); + } + + [Mono.Util.MonoPInvokeCallback(typeof(SQLiteFinalCallback))] + internal static void final_callback(IntPtr context) + { + var handle = GCHandle.FromIntPtr(UnsafeNativeMethods.sqlite3_user_data(context)); + var func = (FunctionData)handle.Target; + func.FuncFinal(context); + } + + [Mono.Util.MonoPInvokeCallback(typeof(SQLiteFinalCallback))] + internal static void destroy_callback(IntPtr context) + { + GCHandle.FromIntPtr(context).Free(); + } +#endif + internal override int ContextCollateCompare(CollationEncodingEnum enc, IntPtr context, string s1, string s2) { #if !SQLITE_STANDARD @@ -865,6 +929,17 @@ namespace Mono.Data.Sqlite return UnsafeNativeMethods.sqlite3_aggregate_context(context, 1); } +#if MONOTOUCH + internal override void SetPassword(byte[] passwordBytes) + { + throw new NotImplementedException (); + } + + internal override void ChangePassword(byte[] newPasswordBytes) + { + throw new NotImplementedException (); + } +#else internal override void SetPassword(byte[] passwordBytes) { int n = UnsafeNativeMethods.sqlite3_key(_sql, passwordBytes, passwordBytes.Length); @@ -876,13 +951,14 @@ namespace Mono.Data.Sqlite int n = UnsafeNativeMethods.sqlite3_rekey(_sql, newPasswordBytes, (newPasswordBytes == null) ? 0 : newPasswordBytes.Length); if (n > 0) throw new SqliteException(n, SQLiteLastError()); } +#endif #if MONOTOUCH SQLiteUpdateCallback update_callback; SQLiteCommitCallback commit_callback; SQLiteRollbackCallback rollback_callback; - [MonoTouch.MonoPInvokeCallback (typeof (SQLiteUpdateCallback))] + [Mono.Util.MonoPInvokeCallback (typeof (SQLiteUpdateCallback))] static void update (IntPtr puser, int type, IntPtr database, IntPtr table, Int64 rowid) { SQLite3 instance = GCHandle.FromIntPtr (puser).Target as SQLite3; @@ -898,7 +974,7 @@ namespace Mono.Data.Sqlite UnsafeNativeMethods.sqlite3_update_hook (_sql, update, GCHandle.ToIntPtr (gch)); } - [MonoTouch.MonoPInvokeCallback (typeof (SQLiteCommitCallback))] + [Mono.Util.MonoPInvokeCallback (typeof (SQLiteCommitCallback))] static int commit (IntPtr puser) { SQLite3 instance = GCHandle.FromIntPtr (puser).Target as SQLite3; @@ -914,7 +990,7 @@ namespace Mono.Data.Sqlite UnsafeNativeMethods.sqlite3_commit_hook (_sql, commit, GCHandle.ToIntPtr (gch)); } - [MonoTouch.MonoPInvokeCallback (typeof (SQLiteRollbackCallback))] + [Mono.Util.MonoPInvokeCallback (typeof (SQLiteRollbackCallback))] static void rollback (IntPtr puser) { SQLite3 instance = GCHandle.FromIntPtr (puser).Target as SQLite3;