// $Header$ using System; namespace Community.CsharpSqlite { using Vdbe = Sqlite3.Vdbe; /// /// C#-SQLite wrapper with functions for opening, closing and executing queries. /// public class SQLiteVdbe { private Vdbe vm = null; private string LastError = ""; private int LastResult = 0; /// /// Creates new instance of SQLiteVdbe class by compiling a statement /// /// /// Vdbe public SQLiteVdbe( SQLiteDatabase db, String query ) { vm = null; // prepare and compile #if NET_35 Sqlite3.PrepareV2NoTail #else Sqlite3.sqlite3_prepare_v2 #endif ( db.Connection(), query, query.Length, ref vm, 0 ); } /// /// Return Virtual Machine Pointer /// /// /// Vdbe public Vdbe VirtualMachine() { return vm; } /// /// /// BindInteger /// /// /// /// LastResult public int BindInteger( int index, int bInteger ) { if ( ( LastResult = #if NET_35 Sqlite3.BindInt #else Sqlite3.sqlite3_bind_int #endif ( vm, index, bInteger ) ) == Sqlite3.SQLITE_OK ) { LastError = ""; } else { LastError = "Error " + LastError + "binding Integer [" + bInteger + "]"; } return LastResult; } /// /// /// BindLong /// /// /// /// LastResult public int BindLong( int index, long bLong ) { if ( ( LastResult = #if NET_35 Sqlite3.BindInt64 #else Sqlite3.sqlite3_bind_int64 #endif ( vm, index, bLong ) ) == Sqlite3.SQLITE_OK ) { LastError = ""; } else { LastError = "Error " + LastError + "binding Long [" + bLong + "]"; } return LastResult; } /// /// BindText /// /// /// /// LastResult public int BindText( int index, string bText ) { if ( ( LastResult = #if NET_35 Sqlite3.BindText #else Sqlite3.sqlite3_bind_text #endif ( vm, index, bText, -1, null ) ) == Sqlite3.SQLITE_OK ) { LastError = ""; } else { LastError = "Error " + LastError + "binding Text [" + bText + "]"; } return LastResult; } /// /// Execute statement /// /// /// LastResult public int ExecuteStep() { // Execute the statement int LastResult = #if NET_35 Sqlite3.Step #else Sqlite3.sqlite3_step #endif ( vm ); return LastResult; } /// /// Returns Result column as Long /// /// /// Result column public long Result_Long( int index ) { return #if NET_35 Sqlite3.ColumnInt64 #else Sqlite3.sqlite3_column_int64 #endif ( vm, index ); } /// /// Returns Result column as Text /// /// /// Result column public string Result_Text( int index ) { return #if NET_35 Sqlite3.ColumnText #else Sqlite3.sqlite3_column_text #endif ( vm, index ); } /// /// Returns Count of Result Rows /// /// /// Count of Results public int ResultColumnCount() { return vm.pResultSet == null ? 0 : vm.pResultSet.Length; } /// /// Reset statement /// /// /// public void Reset() { // Reset the statment so it's ready to use again #if NET_35 Sqlite3.Reset #else Sqlite3.sqlite3_reset #endif ( vm ); } /// /// Closes statement /// /// /// LastResult public void Close() { #if NET_35 Sqlite3.Finalize #else Sqlite3.sqlite3_finalize #endif ( vm ); } } }