Exemplo n.º 1
0
            private static object[] buildPyParams(CodeContext context, Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] argv)
            {
                object[] args = new object[argc];

                for (int i = 0; i < argc; ++i)
                {
                    sqlite3_value cur_value    = argv[i];
                    object        cur_py_value = null;

                    switch (Sqlite3.sqlite3_value_type(cur_value))
                    {
                    case Sqlite3.SQLITE_INTEGER:
                        cur_py_value = (int)Sqlite3.sqlite3_value_int64(cur_value);
                        break;

                    case Sqlite3.SQLITE_FLOAT:
                        cur_py_value = Sqlite3.sqlite3_value_double(cur_value);
                        break;

                    case Sqlite3.SQLITE_TEXT:
                        cur_py_value = Sqlite3.sqlite3_value_text(cur_value);
                        break;

                    case Sqlite3.SQLITE_BLOB:
                        byte[]       result = Sqlite3.sqlite3_value_blob(cur_value);
                        PythonBuffer buffer = new PythonBuffer(context, result);
                        cur_py_value = buffer;
                        break;

                    case Sqlite3.SQLITE_NULL:
                    default:
                        cur_py_value = null;
                        break;
                    }

                    args[i] = cur_py_value;
                }

                return(args);
            }
Exemplo n.º 2
0
            private static object[] buildPyParams(CodeContext context, Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] argv)
            {
                object[] args = new object[argc];

                for (int i = 0; i < argc; ++i)
                {
                    sqlite3_value cur_value    = argv[i];
                    object        cur_py_value = null;

                    switch (Sqlite3.sqlite3_value_type(cur_value))
                    {
                    case Sqlite3.SQLITE_INTEGER:
                        cur_py_value = (int)Sqlite3.sqlite3_value_int64(cur_value);
                        break;

                    case Sqlite3.SQLITE_FLOAT:
                        cur_py_value = Sqlite3.sqlite3_value_double(cur_value);
                        break;

                    case Sqlite3.SQLITE_TEXT:
                        cur_py_value = Sqlite3.sqlite3_value_text(cur_value);
                        break;

                    case Sqlite3.SQLITE_BLOB:
                        cur_py_value = new Bytes(Sqlite3.sqlite3_value_blob(cur_value));     // TODO: avoid creating a copy
                        break;

                    case Sqlite3.SQLITE_NULL:
                    default:
                        cur_py_value = null;
                        break;
                    }

                    args[i] = cur_py_value;
                }

                return(args);
            }
 internal SqliteValueHandle(Community.CsharpSqlite.Sqlite3.Mem db)
 {
     _handle = db;
 }
Exemplo n.º 4
0
                public void stepCallback(Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] param)
                {
                    if(instance == null)
                    {
                        try
                        {
                            instance = PythonCalls.Call(context, aggregate_class);
                        }
                        catch(Exception)
                        {
                            Sqlite3.sqlite3_result_error(ctx, "user-defined aggregate's '__init__' method raised error", -1);
                            return;
                        }
                    }

                    try
                    {
                        object step = context.LanguageContext.Operations.GetMember(instance, "step");
                        object[] args = buildPyParams(context, ctx, argc, param);

                        PythonCalls.CallWithKeywordArgs(context, step, args, new Dictionary<object, object>());
                    }
                    catch(Exception e)
                    {
                        if(e is MissingMemberException)
                            throw;

                        Sqlite3.sqlite3_result_error(ctx, "user-defined aggregate's 'step' method raised error", -1);
                    }
                }
Exemplo n.º 5
0
            private static object[] buildPyParams(CodeContext context, Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] argv)
            {
                object[] args = new object[argc];

                for(int i = 0; i < argc; ++i)
                {
                    sqlite3_value cur_value = argv[i];
                    object cur_py_value = null;

                    switch(Sqlite3.sqlite3_value_type(cur_value))
                    {
                        case Sqlite3.SQLITE_INTEGER:
                            cur_py_value = (int)Sqlite3.sqlite3_value_int64(cur_value);
                            break;

                        case Sqlite3.SQLITE_FLOAT:
                            cur_py_value = Sqlite3.sqlite3_value_double(cur_value);
                            break;

                        case Sqlite3.SQLITE_TEXT:
                            cur_py_value = Sqlite3.sqlite3_value_text(cur_value);
                            break;

                        case Sqlite3.SQLITE_BLOB:
                            byte[] result = Sqlite3.sqlite3_value_blob(cur_value);
                            PythonBuffer buffer = new PythonBuffer(context, result);
                            cur_py_value = buffer;
                            break;

                        case Sqlite3.SQLITE_NULL:
                        default:
                            cur_py_value = null;
                            break;
                    }

                    args[i] = cur_py_value;
                }

                return args;
            }
Exemplo n.º 6
0
            private static void callUserFunction(Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] argv)
            {
                object[] data = (object[])Sqlite3.sqlite3_user_data(ctx);
                CodeContext context = (CodeContext)data[0];
                object func = data[1];

                object[] args = buildPyParams(context, ctx, argc, argv);

                try
                {
                    object result = PythonCalls.CallWithKeywordArgs(context, func, args, emptyKwargs);
                    setResult(ctx, result);
                }
                catch(Exception)
                {
                    Sqlite3.sqlite3_result_error(ctx, "user-defined function raised exception", -1);
                }
            }