-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathSQLiteVdbe.cs
166 lines (148 loc) · 3.93 KB
/
SQLiteVdbe.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// $Header$
using System;
using System.Collections.Generic;
using System.Text;
using CS_SQLite3;
using System.Data;
using System.Collections;
namespace CS_SQLite3
{
using sqlite = CSSQLite.sqlite3;
using Vdbe = CSSQLite.Vdbe;
/// <summary>
/// C#-SQLite wrapper with functions for opening, closing and executing queries.
/// </summary>
public class SQLiteVdbe
{
private Vdbe vm = null;
private string LastError = "";
private int LastResult = 0;
/// <summary>
/// Creates new instance of SQLiteVdbe class by compiling a statement
/// </summary>
/// <param name="query"></param>
/// <returns>Vdbe</returns>
public SQLiteVdbe( SQLiteDatabase db, String query )
{
vm = null;
// prepare and compile
CSSQLite.sqlite3_prepare_v2( db.Connection(), query, query.Length, ref vm, 0 );
}
/// <summary>
/// Return Virtual Machine Pointer
/// </summary>
/// <param name="query"></param>
/// <returns>Vdbe</returns>
public Vdbe VirtualMachine()
{
return vm;
}
/// <summary>
/// <summary>
/// BindInteger
/// </summary>
/// <param name="index"></param>
/// <param name="bInteger"></param>
/// <returns>LastResult</returns>
public int BindInteger(int index, int bInteger )
{
if ( (LastResult = CSSQLite.sqlite3_bind_int( vm, index, bInteger ))== CSSQLite.SQLITE_OK )
{ LastError = ""; }
else
{
LastError = "Error " + LastError + "binding Integer [" + bInteger + "]";
}
return LastResult;
}
/// <summary>
/// <summary>
/// BindLong
/// </summary>
/// <param name="index"></param>
/// <param name="bLong"></param>
/// <returns>LastResult</returns>
public int BindLong( int index, long bLong )
{
if ( ( LastResult = CSSQLite.sqlite3_bind_int64( vm, index, bLong ) ) == CSSQLite.SQLITE_OK )
{ LastError = ""; }
else
{
LastError = "Error " + LastError + "binding Long [" + bLong + "]";
}
return LastResult;
}
/// <summary>
/// BindText
/// </summary>
/// <param name="index"></param>
/// <param name="bLong"></param>
/// <returns>LastResult</returns>
public int BindText( int index, string bText )
{
if ( ( LastResult = CSSQLite.sqlite3_bind_text( vm, index, bText ,-1,null) ) == CSSQLite.SQLITE_OK )
{ LastError = ""; }
else
{
LastError = "Error " + LastError + "binding Text [" + bText + "]";
}
return LastResult;
}
/// <summary>
/// Execute statement
/// </summary>
/// </param>
/// <returns>LastResult</returns>
public int ExecuteStep( )
{
// Execute the statement
int LastResult = CSSQLite.sqlite3_step( vm );
return LastResult;
}
/// <summary>
/// Returns Result column as Long
/// </summary>
/// </param>
/// <returns>Result column</returns>
public long Result_Long(int index)
{
return CSSQLite.sqlite3_column_int64( vm, index );
}
/// <summary>
/// Returns Result column as Text
/// </summary>
/// </param>
/// <returns>Result column</returns>
public string Result_Text( int index )
{
return CSSQLite.sqlite3_column_text( vm, index );
}
/// <summary>
/// Returns Count of Result Rows
/// </summary>
/// </param>
/// <returns>Count of Results</returns>
public int ResultColumnCount( )
{
return vm.pResultSet == null ? 0 : vm.pResultSet.Length;
}
/// <summary>
/// Reset statement
/// </summary>
/// </param>
/// </returns>
public void Reset()
{
// Reset the statment so it's ready to use again
CSSQLite.sqlite3_reset( vm );
}
/// <summary>
/// Closes statement
/// </summary>
/// </param>
/// <returns>LastResult</returns>
public void Close()
{
CSSQLite.sqlite3_finalize( ref vm );
}
}
}