Skip to content

Commit e8607b7

Browse files
committed
* Kisebb fix.
1 parent 20ef771 commit e8607b7

4 files changed

Lines changed: 27 additions & 145 deletions

File tree

System.Data.SQLite.Benchmark/Classes/SQLiteDatabase.cs

Lines changed: 14 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System;
22
using System.Data;
3+
using System.Data.SQLite;
34
using System.Collections;
45

5-
namespace System.Data.SQLite
6+
namespace System.Data.SQLite.Benchmark
67
{
78
using sqlite = Sqlite3.sqlite3;
89
using Vdbe = Sqlite3.Vdbe;
@@ -39,13 +40,7 @@ public SQLiteDatabase(String DatabaseName)
3940
public void OpenDatabase(String DatabaseName)
4041
{
4142
// opens database
42-
if(
43-
#if NET_35
44-
Sqlite3.Open
45-
#else
46-
Sqlite3.sqlite3_open
47-
#endif
48-
(DatabaseName, out db) != Sqlite3.SQLITE_OK)
43+
if(Sqlite3.sqlite3_open(DatabaseName, out db) != Sqlite3.SQLITE_OK)
4944
{
5045
// if there is some error, database pointer is set to 0 and exception is throws
5146
db = null;
@@ -61,12 +56,7 @@ public void CloseDatabase()
6156
// closes the database if there is one opened
6257
if(db != null)
6358
{
64-
#if NET_35
65-
Sqlite3.Close
66-
#else
67-
Sqlite3.sqlite3_close
68-
#endif
69-
(db);
59+
Sqlite3.sqlite3_close(db);
7060
}
7161
}
7262

@@ -109,13 +99,7 @@ public void ExecuteNonQuery(String query)
10999
Sqlite3.exec(db, query, 0, 0, 0);
110100
// if there is error, excetion is thrown
111101
if(db.errCode != Sqlite3.SQLITE_OK)
112-
throw new Exception("Error with executing non-query: \"" + query + "\"!\n" +
113-
#if NET_35
114-
Sqlite3.Errmsg
115-
#else
116-
Sqlite3.sqlite3_errmsg
117-
#endif
118-
(db));
102+
throw new Exception("Error with executing non-query: \"" + query + "\"!\n" + Sqlite3.sqlite3_errmsg(db));
119103
}
120104

121105
/// <summary>
@@ -155,73 +139,37 @@ private int ReadNextRow(Vdbe vm, DataTable table)
155139
}
156140

157141
int resultType;
158-
if((resultType =
159-
#if NET_35
160-
Sqlite3.Step
161-
#else
162-
Sqlite3.sqlite3_step
163-
#endif
164-
(vm)) == Sqlite3.SQLITE_ROW)
142+
if((resultType = Sqlite3.sqlite3_step(vm)) == Sqlite3.SQLITE_ROW)
165143
{
166144
object[] columnValues = new object[columnCount];
167145

168146
for(int i = 0; i < columnCount; i++)
169147
{
170-
int columnType =
171-
#if NET_35
172-
Sqlite3.ColumnType
173-
#else
174-
Sqlite3.sqlite3_column_type
175-
#endif
176-
(vm, i);
148+
int columnType = Sqlite3.sqlite3_column_type(vm, i);
177149
switch(columnType)
178150
{
179151
case Sqlite3.SQLITE_INTEGER:
180152
{
181153
table.Columns[i].DataType = typeof(Int64);
182-
columnValues[i] =
183-
#if NET_35
184-
Sqlite3.ColumnInt
185-
#else
186-
Sqlite3.sqlite3_column_int
187-
#endif
188-
(vm, i);
154+
columnValues[i] = Sqlite3.sqlite3_column_int(vm, i);
189155
break;
190156
}
191157
case Sqlite3.SQLITE_FLOAT:
192158
{
193159
table.Columns[i].DataType = typeof(Double);
194-
columnValues[i] =
195-
#if NET_35
196-
Sqlite3.ColumnDouble
197-
#else
198-
Sqlite3.sqlite3_column_double
199-
#endif
200-
(vm, i);
160+
columnValues[i] = Sqlite3.sqlite3_column_double(vm, i);
201161
break;
202162
}
203163
case Sqlite3.SQLITE_TEXT:
204164
{
205165
table.Columns[i].DataType = typeof(String);
206-
columnValues[i] =
207-
#if NET_35
208-
Sqlite3.ColumnText
209-
#else
210-
Sqlite3.sqlite3_column_text
211-
#endif
212-
(vm, i);
166+
columnValues[i] = Sqlite3.sqlite3_column_text(vm, i);
213167
break;
214168
}
215169
case Sqlite3.SQLITE_BLOB:
216170
{
217171
table.Columns[i].DataType = typeof(Byte[]);
218-
columnValues[i] =
219-
#if NET_35
220-
Sqlite3.ColumnBlob
221-
#else
222-
Sqlite3.sqlite3_column_blob
223-
#endif
224-
(vm, i);
172+
columnValues[i] = Sqlite3.sqlite3_column_blob(vm, i);
225173
break;
226174
}
227175
default:
@@ -244,34 +192,16 @@ private int ReadColumnNames(Vdbe vm, DataTable table)
244192
String columnName = "";
245193
int columnType = 0;
246194
// returns number of columns returned by statement
247-
int columnCount =
248-
#if NET_35
249-
Sqlite3.ColumnCount
250-
#else
251-
Sqlite3.sqlite3_column_count
252-
#endif
253-
(vm);
195+
int columnCount = Sqlite3.sqlite3_column_count(vm);
254196
object[] columnValues = new object[columnCount];
255197

256198
try
257199
{
258200
// reads columns one by one
259201
for(int i = 0; i < columnCount; i++)
260202
{
261-
columnName =
262-
#if NET_35
263-
Sqlite3.ColumnName
264-
#else
265-
Sqlite3.sqlite3_column_name
266-
#endif
267-
(vm, i);
268-
columnType =
269-
#if NET_35
270-
Sqlite3.ColumnType
271-
#else
272-
Sqlite3.sqlite3_column_type
273-
#endif
274-
(vm, i);
203+
columnName = Sqlite3.sqlite3_column_name(vm, i);
204+
columnType = Sqlite3.sqlite3_column_type(vm, i);
275205

276206
switch(columnType)
277207
{

System.Data.SQLite.Benchmark/Classes/SQLiteVdbe.cs

Lines changed: 11 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
2+
using System.Data.SQLite;
23

3-
namespace System.Data.SQLite
4+
namespace System.Data.SQLite.Benchmark
45
{
56
using Vdbe = Sqlite3.Vdbe;
67

@@ -23,12 +24,7 @@ public SQLiteVdbe(SQLiteDatabase db, String query)
2324
vm = null;
2425

2526
// prepare and compile
26-
#if NET_35
27-
Sqlite3.PrepareV2NoTail
28-
#else
29-
Sqlite3.sqlite3_prepare_v2
30-
#endif
31-
(db.Connection(), query, query.Length, ref vm, 0);
27+
Sqlite3.sqlite3_prepare_v2(db.Connection(), query, query.Length, ref vm, 0);
3228
}
3329

3430
/// <summary>
@@ -50,13 +46,7 @@ public Vdbe VirtualMachine()
5046
/// <returns>LastResult</returns>
5147
public int BindInteger(int index, int bInteger)
5248
{
53-
if((LastResult =
54-
#if NET_35
55-
Sqlite3.BindInt
56-
#else
57-
Sqlite3.sqlite3_bind_int
58-
#endif
59-
(vm, index, bInteger)) == Sqlite3.SQLITE_OK)
49+
if((LastResult = Sqlite3.sqlite3_bind_int(vm, index, bInteger)) == Sqlite3.SQLITE_OK)
6050
{
6151
LastError = "";
6252
}
@@ -76,13 +66,7 @@ public int BindInteger(int index, int bInteger)
7666
/// <returns>LastResult</returns>
7767
public int BindLong(int index, long bLong)
7868
{
79-
if((LastResult =
80-
#if NET_35
81-
Sqlite3.BindInt64
82-
#else
83-
Sqlite3.sqlite3_bind_int64
84-
#endif
85-
(vm, index, bLong)) == Sqlite3.SQLITE_OK)
69+
if((LastResult = Sqlite3.sqlite3_bind_int64(vm, index, bLong)) == Sqlite3.SQLITE_OK)
8670
{
8771
LastError = "";
8872
}
@@ -101,13 +85,7 @@ public int BindLong(int index, long bLong)
10185
/// <returns>LastResult</returns>
10286
public int BindText(int index, string bText)
10387
{
104-
if((LastResult =
105-
#if NET_35
106-
Sqlite3.BindText
107-
#else
108-
Sqlite3.sqlite3_bind_text
109-
#endif
110-
(vm, index, bText, -1, null)) == Sqlite3.SQLITE_OK)
88+
if((LastResult = Sqlite3.sqlite3_bind_text(vm, index, bText, -1, null)) == Sqlite3.SQLITE_OK)
11189
{
11290
LastError = "";
11391
}
@@ -126,13 +104,7 @@ public int BindText(int index, string bText)
126104
public int ExecuteStep()
127105
{
128106
// Execute the statement
129-
int LastResult =
130-
#if NET_35
131-
Sqlite3.Step
132-
#else
133-
Sqlite3.sqlite3_step
134-
#endif
135-
(vm);
107+
int LastResult = Sqlite3.sqlite3_step(vm);
136108
return LastResult;
137109
}
138110

@@ -143,13 +115,7 @@ public int ExecuteStep()
143115
/// <returns>Result column</returns>
144116
public long Result_Long(int index)
145117
{
146-
return
147-
#if NET_35
148-
Sqlite3.ColumnInt64
149-
#else
150-
Sqlite3.sqlite3_column_int64
151-
#endif
152-
(vm, index);
118+
return Sqlite3.sqlite3_column_int64(vm, index);
153119
}
154120

155121
/// <summary>
@@ -159,13 +125,7 @@ public long Result_Long(int index)
159125
/// <returns>Result column</returns>
160126
public string Result_Text(int index)
161127
{
162-
return
163-
#if NET_35
164-
Sqlite3.ColumnText
165-
#else
166-
Sqlite3.sqlite3_column_text
167-
#endif
168-
(vm, index);
128+
return Sqlite3.sqlite3_column_text(vm, index);
169129
}
170130

171131
/// <summary>
@@ -186,12 +146,7 @@ public int ResultColumnCount()
186146
public void Reset()
187147
{
188148
// Reset the statment so it's ready to use again
189-
#if NET_35
190-
Sqlite3.Reset
191-
#else
192-
Sqlite3.sqlite3_reset
193-
#endif
194-
(vm);
149+
Sqlite3.sqlite3_reset(vm);
195150
}
196151

197152
/// <summary>
@@ -201,12 +156,7 @@ public void Reset()
201156
/// <returns>LastResult</returns>
202157
public void Close()
203158
{
204-
#if NET_35
205-
Sqlite3.Finalize
206-
#else
207-
Sqlite3.sqlite3_finalize
208-
#endif
209-
(vm);
159+
Sqlite3.sqlite3_finalize(vm);
210160
}
211161
}
212162
}

System.Data.SQLite.Benchmark/src/Benchmark.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Data;
44
using System.Data.SQLite;
5+
using System.Data.SQLite.Benchmark;
56
using System.Diagnostics;
67

78
/*

Tests/System.Data.SQLite.UnitTests/Stress.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Diagnostics;
33
using Xunit;
44
using System.Data.SQLite;
5+
using System.Data.SQLite.Benchmark;
56

67
namespace Community.CsharpSQLite.UnitTests
78
{

0 commit comments

Comments
 (0)