Exemplo n.º 1
0
        public void ExecuteUpdate(string query, params string[] args)
        {
            IntPtr statement = PrepareStatement(query, args);

            try {
                if (SQLiteNativeMethods.sqlite3_step(statement) != SQLITE_DONE)
                {
                    throw new ApplicationException("Execute update result not DONE: " + ErrMsg());
                }
            } finally {
                FinalizeStatement(statement);
            }
        }
Exemplo n.º 2
0
        public DataTable ExecuteQuery(string query, params string[] args)
        {
            IntPtr statement = PrepareStatement(query, args);

            DataTable result = new DataTable();

            try {
                int column_count = SQLiteNativeMethods.sqlite3_column_count(statement);

                for (int i = 0; i < column_count; i++)
                {
                    IntPtr col_name = SQLiteNativeMethods.sqlite3_column_origin_name16(statement, i);
                    result.Columns.Add(UniPtrToString(col_name), typeof(string));
                }

                while (SQLiteNativeMethods.sqlite3_step(statement) == SQLITE_ROW)
                {
                    string[] row = new string[column_count];

                    for (int i = 0; i < column_count; i++)
                    {
                        if (SQLiteNativeMethods.sqlite3_column_type(statement, i) != TypeAffinity.Text)
                        {
                            throw new ApplicationException(String.Format("Column {0} is not string", i));
                        }
                        IntPtr val = SQLiteNativeMethods.sqlite3_column_text16(statement, i);
                        row [i] = UniPtrToString(val) ?? "";
                    }

                    result.Rows.Add(row);
                }
            } finally {
                FinalizeStatement(statement);
            }

            return(result);
        }