{"id":229803,"date":"2014-07-14T15:30:03","date_gmt":"2014-07-14T11:30:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=229803"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=229803","title":{"rendered":"<span class=\"post_title\">\u041b\u0435\u0447\u0438\u043c SQLite \u0432 Monotouch \u0438\u043b\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043f\u043e\u043b\u044c\u0437\u0430 \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0438<\/span>"},"content":{"rendered":"<div class=\"content html_format\">     \t\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0434\u0435\u0442\u0438\u0449\u0435\u043c Xamarin \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0438 \u043f\u043e\u043b\u043d\u0430 \u0441\u044e\u0440\u043f\u0440\u0438\u0437\u043e\u0432, \u043a\u0430\u043a \u0432 \u0445\u043e\u0440\u043e\u0448\u0435\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u0441\u043b\u043e\u0432\u0430, \u0442\u0430\u043a \u0438 \u0432 \u043f\u043b\u043e\u0445\u043e\u043c. \u041e\u0434\u043d\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0440\u0435\u0448\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0433\u0443\u0433\u043b\u0430 \u0438 StackOverflow, \u0434\u0440\u0443\u0433\u0438\u0435 \u0436\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432, \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0438 \u0438 \u0442\u0440\u0435\u0445 \u043a\u0440\u0443\u0436\u0435\u043a \u0447\u0430\u044f \u0440\u0435\u0448\u0438\u0442\u044c \u043e\u0434\u043d\u0443 \u043f\u0440\u0435\u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u0435\u0439\u0448\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443.<\/p>\n<p>  <a name=\"habracut\"><\/a><br \/>  \u0410 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e Monotouch \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 SQLite. \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0445 \u0447\u0435\u0440\u0435\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 API \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435 \u0432\u0438\u0434\u0430:  <\/p>\n<blockquote><p>Attempting to JIT compile method &#8216;(wrapper native-to-managed) Mono.Data.Sqlite.SqliteFunction:ScalarCallback (intptr,int,intptr)&#8217; while running with &#8212;aot-only. Seehttp:\/\/docs.xamarin.com\/ios\/about\/limitations for more information.<\/p><\/blockquote>\n<p>  \u0410 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043b\u0435\u0437\u0442\u044c \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 mono, \u0447\u0442\u043e \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c: <a href=\"https:\/\/github.com\/mono\/mono\">https:\/\/github.com\/mono\/mono<\/a>. \u041a\u043e\u0434 SQLite \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043f\u043e \u043f\u0443\u0442\u0438: \\mono\\mcs\\class\\Mono.Data.Sqlite\\Mono.Data.Sqlite_2.0.<\/p>\n<h5>\u041f\u043e\u0438\u0441\u043a \u043f\u0440\u0438\u0447\u0438\u043d\u044b<\/h5>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u043c <a href=\"http:\/\/docs.xamarin.com\/ios\/about\/limitations\">\u0441\u0442\u0430\u0442\u044c\u044e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b monotouch<\/a>. \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430, \u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0438\u0433\u0440\u0430\u0442\u044c \u0440\u043e\u043b\u044c Reverce Callbacks \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f:  <\/p>\n<ol>\n<li>\u041c\u0435\u0442\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 MonoPInvokeCallbackAttribute<\/li>\n<li>\u041e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438<\/li>\n<\/ol>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u0439\u0434\u0435\u043c \u043a\u043e\u0434 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u043c\u0443 API SQLite, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u043b\u0430\u0441\u0441 UnsafeNativeMethods. \u0412 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435 \u043f\u043e SQLite \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e, \u0447\u0442\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 sqlite3_create_function. \u0421\u0430\u043c\u043e \u0441\u043e\u0431\u043e\u0439, \u043e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 DllImport. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430.<br \/>  \u0421\u0430\u043c \u043c\u0435\u0442\u043e\u0434 sqlite3_create_function \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0437 SQLite3.CreateFunction():  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u0435\u0442\u043e\u0434 CreateFunction<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">  internal override void CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func, SQLiteCallback funcstep, SQLiteFinalCallback funcfinal)         {             int n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal);             if (n == 0)                  n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal);             if (n &gt; 0) throw new SqliteException(n, SQLiteLastError());         } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 SQLiteFunction.BindFunctions:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u0435\u0442\u043e\u0434 BindFunctions<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">internal static SqliteFunction[] BindFunctions(SQLiteBase sqlbase)     {       SqliteFunction f;       List&lt;SqliteFunction&gt; lFunctions = new List&lt;SqliteFunction&gt;();       foreach (SqliteFunctionAttribute pr in _registeredFunctions)       {         f = (SqliteFunction)Activator.CreateInstance(pr._instanceType);         f._base = sqlbase;         f._InvokeFunc = (pr.FuncType == FunctionType.Scalar)              ? new SQLiteCallback(f.ScalarCallback) : null;         f._StepFunc = (pr.FuncType == FunctionType.Aggregate)              ? new SQLiteCallback(f.StepCallback) : null;         f._FinalFunc = (pr.FuncType == FunctionType.Aggregate)              ? new SQLiteFinalCallback(f.FinalCallback) : null;         f._CompareFunc = (pr.FuncType == FunctionType.Collation)              ? new SQLiteCollation(f.CompareCallback) : null;         f._CompareFunc16 = (pr.FuncType == FunctionType.Collation)              ? new SQLiteCollation(f.CompareCallback16) : null;          if (pr.FuncType != FunctionType.Collation)           sqlbase.CreateFunction(pr.Name, pr.Arguments, (f is SqliteFunctionEx)               , f._InvokeFunc, f._StepFunc, f._FinalFunc);         else           sqlbase.CreateCollation(pr.Name, f._CompareFunc, f._CompareFunc16);         lFunctions.Add(f);       }       SqliteFunction[] arFunctions = new SqliteFunction[lFunctions.Count];       lFunctions.CopyTo(arFunctions, 0);       return arFunctions;     }   } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0432 \u043c\u0435\u0442\u043e\u0434 CreateFunction: \u043e\u043d\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u044b \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 SQLiteFunction. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 ScalarCallback:  <\/p>\n<pre><code class=\"cs\">    internal void ScalarCallback(IntPtr context, int nArgs, IntPtr argsptr)     {       _context = context;       SetReturnValue(context, Invoke(ConvertParams(nArgs, argsptr)));     } <\/code><\/pre>\n<p>  \u0418 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 MonoPInvokeCallbackAttribute. \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0430.<\/p>\n<h5>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h5>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f:  <\/p>\n<ol>\n<li>\u0427\u0435\u0440\u0435\u0437 DllImport \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a SQLite \u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e sqlite3_create_function \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e<\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 UnsafeNativeMethods, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0432 Mono.Data.SQLite<\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 SQLite3.CreateFunction<\/li>\n<\/ol>\n<p>  \u0412\u0441\u0435 \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u043e \u0441\u0432\u043e\u0435\u043c\u0443 \u0445\u043e\u0440\u043e\u0448\u0438, \u043d\u043e \u044f \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u043f\u043e\u0448\u0435\u043b \u043f\u043e \u0442\u0440\u0435\u0442\u044c\u0435\u043c\u0443 \u043f\u0443\u0442\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u043e\u0431\u0435\u0449\u0430\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u043c\u0435\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e \u0432 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<p>  \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u043a\u043e\u0434\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u043d\u0430 <a href=\"https:\/\/github.com\/AleksandrKugushev\/MonotouchSqliteFunctionsSample\">\u0433\u0438\u0442\u0445\u0430\u0431\u0435<\/a>.<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 SQLite3 \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u0432 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u043b\u0435 _sql \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 SqliteConnection. \u0422\u0430\u043a \u0447\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u044e:  <\/p>\n<pre><code class=\"cs\">FieldInfo connection_sql = connection.GetType ().GetField (&quot;_sql&quot;, BindingFlags.Instance | BindingFlags.NonPublic); _sqlite3 = connection_sql.GetValue (connection); <\/code><\/pre>\n<p>  \u0433\u0434\u0435 connection \u2014 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 SqliteConnection.<br \/>  \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a CreateFunction \u0442\u0430\u043a \u0436\u0435 \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c:  <\/p>\n<pre><code class=\"cs\">MethodInfo CreateFunction = _sqlite3.GetType ().GetMethod (&quot;CreateFunction&quot;, BindingFlags.Instance | BindingFlags.NonPublic); <\/code><\/pre>\n<p>   \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430:  <\/p>\n<pre><code class=\"cs\">static void ToLowerCallback(IntPtr context, int nArgs, IntPtr argptr) { ... } <\/code><\/pre>\n<p>  \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 SQLiteCallback:  <\/p>\n<pre><code class=\"cs\">Type SQLiteCallbackDelegate = connection.GetType ().Assembly.GetType (&quot;Mono.Data.Sqlite.SQLiteCallback&quot;); var callback = Delegate.CreateDelegate (SQLiteCallbackDelegate,\ttypeof(DbFunctions).GetMethod (&quot;ToLowerCallback&quot;, BindingFlags.Static | BindingFlags.NonPublic)); CreateFunction.Invoke (_sqlite3, new object[] { \t\t\t\t&quot;TOLOWER&quot;, \t\t\t\t1, \t\t\t\tfalse, \t\t\t\tcallback , \t\t\t\tnull, \t\t\t\tnull \t\t\t}); <\/code><\/pre>\n<p>   \u041d\u043e \u043a\u0430\u043a \u0436\u0435 \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 MonoPInvokeCallback, \u0435\u0441\u043b\u0438 \u043e\u043d \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0442\u0438\u043f \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430? \u0414\u0430 \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e! \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"cs\">[AttributeUsage (AttributeTargets.Method)] sealed class MonoPInvokeCallbackAttribute : Attribute { \t\tpublic MonoPInvokeCallbackAttribute (Type t) {} \t} <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043d\u0435 \u0432\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430? \u041d\u0435\u0442, \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a: \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c typeof(object), \u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 AOT \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043d\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435. \u0422\u0430\u043a \u0447\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u043b\u044c\u0448\u0438\u0432\u044b\u0439 \u0434\u0435\u043b\u0435\u0433\u0430\u0442  <\/p>\n<pre><code class=\"cs\">public delegate void FakeSQLiteCallback (IntPtr context, int nArgs, IntPtr argptr); <\/code><\/pre>\n<p>  \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442  <\/p>\n<pre><code class=\"cs\">[MonoPInvokeCallback (typeof(FakeSQLiteCallback))] static void ToLowerCallback(IntPtr context, int nArgs, IntPtr argptr) { ... } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435, \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u0440\u0430\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f.<br \/>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443.<\/p>\n<p>  \u0412\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u043a\u043e\u0434\u044b Mono.Data.Sqlite. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u0432 ScalarCallback: \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434\u044b ConvertParams \u0438 SetReturnValue. \u0411\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u044e, \u043d\u043e \u043e\u043d\u0438 \u043d\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435, \u0442\u0430\u043a \u0447\u0442\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u043e\u0441\u044c \u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 SQLiteFunction. \u0422\u0430\u043a \u0447\u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u0438\u0445 \u043b\u043e\u0433\u0438\u043a\u0443 \u0432 \u0441\u0432\u043e\u0435\u043c \u043a\u043e\u0434\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u044e. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u043f\u043e\u043b\u0435\u0439 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0440\u043e\u0433\u043e\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 FieldInfo \u0438 MethodInfo \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">Type sqlite3 = _sqlite3.GetType (); _sqlite3_GetParamValueType = sqlite3.GetMethod (&quot;GetParamValueType&quot;, BindingFlags.Instance | BindingFlags.NonPublic); _sqlite3_GetParamValueInt64 = sqlite3.GetMethod (&quot;GetParamValueInt64&quot;, BindingFlags.Instance | BindingFlags.NonPublic); _sqlite3_GetParamValueDouble = sqlite3.GetMethod (&quot;GetParamValueDouble&quot;, BindingFlags.Instance | BindingFlags.NonPublic); _sqlite3_GetParamValueText = sqlite3.GetMethod (&quot;GetParamValueText&quot;, BindingFlags.Instance | BindingFlags.NonPublic); _sqlite3_GetParamValueBytes = sqlite3.GetMethod (&quot;GetParamValueBytes&quot;, BindingFlags.Instance | BindingFlags.NonPublic); _sqlite3_ToDateTime = sqlite3.BaseType.GetMethod (&quot;ToDateTime&quot;, new Type[] { typeof(string) });  _sqlite3_ReturnNull = sqlite3.GetMethod (&quot;ReturnNull&quot;, BindingFlags.Instance | BindingFlags.NonPublic); _sqlite3_ReturnError = sqlite3.GetMethod (&quot;ReturnError&quot;, BindingFlags.Instance | BindingFlags.NonPublic); _sqlite3_ReturnInt64 = sqlite3.GetMethod (&quot;ReturnInt64&quot;, BindingFlags.Instance | BindingFlags.NonPublic); _sqlite3_ReturnDouble = sqlite3.GetMethod (&quot;ReturnDouble&quot;, BindingFlags.Instance | BindingFlags.NonPublic); _sqlite3_ReturnText = sqlite3.GetMethod (&quot;ReturnText&quot;, BindingFlags.Instance | BindingFlags.NonPublic); _sqlite3_ReturnBlob = sqlite3.GetMethod (&quot;ReturnBlob&quot;, BindingFlags.Instance | BindingFlags.NonPublic); _sqlite3_ToString = sqlite3.GetMethod (&quot;ToString&quot;, new Type[] { typeof(DateTime) }); _sqliteConvert_TypeToAffinity = typeof(SqliteConvert).GetMethod (&quot;TypeToAffinity&quot;, BindingFlags.Static | BindingFlags.NonPublic); <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>   \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041c\u0435\u0442\u043e\u0434\u044b PrepareParameters \u0438 ReturnValue<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">static object[] PrepareParameters (int nArgs, IntPtr argptr) { object[] parms = new object[nArgs]; int[] argint = new int[nArgs]; Marshal.Copy (argptr, argint, 0, nArgs); for (int n = 0; n &lt; nArgs; n++) { \tTypeAffinity affinity = (TypeAffinity)_sqlite3_GetParamValueType.InvokeSqlite ((IntPtr)argint [n]); \tswitch (affinity) { \tcase TypeAffinity.Null: \t\tparms [n] = DBNull.Value; \t\tbreak; \tcase TypeAffinity.Int64: \t\tparms [n] = _sqlite3_GetParamValueInt64.InvokeSqlite ((IntPtr)argint [n]); \t\tbreak; \tcase TypeAffinity.Double: \t\tparms [n] = _sqlite3_GetParamValueDouble.InvokeSqlite ((IntPtr)argint [n]); \t\tbreak; \tcase TypeAffinity.Text: \t\tparms [n] = _sqlite3_GetParamValueText.InvokeSqlite ((IntPtr)argint [n]); \t\tbreak; \tcase TypeAffinity.Blob: \t\tint x; \t\tbyte[] blob; \t\tx = (int)_sqlite3_GetParamValueBytes.InvokeSqlite ((IntPtr)argint [n], 0, null, 0, 0); \t\tblob = new byte[x]; \t\t_sqlite3_GetParamValueBytes.InvokeSqlite ((IntPtr)argint [n], 0, blob, 0, 0); \t\tparms [n] = blob; \t\tbreak; \tcase TypeAffinity.DateTime: \t\tobject text = _sqlite3_GetParamValueText.InvokeSqlite ((IntPtr)argint [n]); \t\tparms [n] = _sqlite3_ToDateTime.InvokeSqlite (text); \t\tbreak; \t} } return parms; }  static void ReturnValue (IntPtr context, object result) { if (result == null || result == DBNull.Value) { \t_sqlite3_ReturnNull.Invoke (_sqlite3, new object[] { context }); \treturn; }  Type t = result.GetType (); if (t == typeof(DateTime)) { \tobject str = _sqlite3_ToString.InvokeSqlite (result); \t_sqlite3_ReturnText.InvokeSqlite (context, str); \treturn; } else { \tException r = result as Exception; \tif (r != null) { \t\t_sqlite3_ReturnError.InvokeSqlite (context, r.Message); \t\treturn; \t} } TypeAffinity resultAffinity = (TypeAffinity)_sqliteConvert_TypeToAffinity.InvokeSqlite (t); switch (resultAffinity) { case TypeAffinity.Null: \t_sqlite3_ReturnNull.InvokeSqlite (context); \treturn; case TypeAffinity.Int64: \t_sqlite3_ReturnInt64.InvokeSqlite (context,\tConvert.ToInt64 (result)); \treturn; case TypeAffinity.Double: \t_sqlite3_ReturnDouble.InvokeSqlite (context, Convert.ToDouble (result)); \treturn; case TypeAffinity.Text: \t_sqlite3_ReturnText.InvokeSqlite (context, result.ToString ()); \treturn; case TypeAffinity.Blob: \t_sqlite3_ReturnBlob.InvokeSqlite (context, (byte[])result); \treturn; } }  static object InvokeSqlite (this MethodInfo mi, params object[] parameters) { return mi.Invoke (_sqlite3, parameters); } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435, \u043d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u0438\u0434:  <\/p>\n<pre><code class=\"cs\">[MonoPInvokeCallback (typeof(FakeSQLiteCallback))] static void ToLowerCallback (IntPtr context, int nArgs, IntPtr argptr) { object[] parms = PrepareParameters (nArgs, argptr); object result = parms [0].ToString ().ToLower (); ReturnValue (context, result); } <\/code><\/pre>\n<h5> \u0412\u044b\u0432\u043e\u0434<\/h5>\n<p>  \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432 \u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0438 \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0438 \u043d\u0430\u043c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u0431\u043e\u0439\u0442\u0438 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b. \u041a\u0430\u043a \u044f \u0432\u044b\u0448\u0435 \u0443\u0436\u0435 \u043f\u0438\u0441\u0430\u043b, \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432\u044b\u043b\u043e\u0436\u0435\u043d \u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435.<br \/>  \u042f \u043d\u0435 \u0441\u0447\u0438\u0442\u0430\u044e \u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u0435\u0440\u043d\u044b\u043c, \u043d\u043e \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0422\u0430\u043a \u0436\u0435 \u044f \u0431\u044b\u043b \u0431\u044b \u0440\u0430\u0434 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0432\u0430\u0448 \u0432\u0430\u0440\u0438\u0430\u043d\u0442.      \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/229803\/\"> http:\/\/habrahabr.ru\/post\/229803\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">     \t\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0434\u0435\u0442\u0438\u0449\u0435\u043c Xamarin \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0438 \u043f\u043e\u043b\u043d\u0430 \u0441\u044e\u0440\u043f\u0440\u0438\u0437\u043e\u0432, \u043a\u0430\u043a \u0432 \u0445\u043e\u0440\u043e\u0448\u0435\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u0441\u043b\u043e\u0432\u0430, \u0442\u0430\u043a \u0438 \u0432 \u043f\u043b\u043e\u0445\u043e\u043c. \u041e\u0434\u043d\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0440\u0435\u0448\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0433\u0443\u0433\u043b\u0430 \u0438 StackOverflow, \u0434\u0440\u0443\u0433\u0438\u0435 \u0436\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432, \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0438 \u0438 \u0442\u0440\u0435\u0445 \u043a\u0440\u0443\u0436\u0435\u043a \u0447\u0430\u044f \u0440\u0435\u0448\u0438\u0442\u044c \u043e\u0434\u043d\u0443 \u043f\u0440\u0435\u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u0435\u0439\u0448\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-229803","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/229803","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=229803"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/229803\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=229803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=229803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=229803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}