Skip to content

Commit f27e73b

Browse files
committed
better bind logic (Oracle), rowArraySize
compile fix, Feature Flags
1 parent ffa3999 commit f27e73b

13 files changed

Lines changed: 552 additions & 256 deletions

File tree

mysql/test.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ unittest {
2929

3030
//auto db = createDatabase("mysql://127.0.0.1/test");
3131

32+
/*
3233
void perf1() {
3334
import std.datetime;
3435
import std.conv;
@@ -69,4 +70,4 @@ void perf1() {
6970
writeln("sum: ", sum);
7071
writeln("time: ", to!Duration(sw2.peek));
7172
}
72-
73+
*/

oracle/dub.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
],
99
"sourcePaths": [".", "../src"],
1010
"libs" : ["occi","clntsh"],
11+
"versions": ["StdLoggerDisableLogging"],
1112
"dependencies": {
1213
},
1314
"configurations": [

oracle/test.d

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ unittest {
77
alias DB = Database!DefaultPolicy;
88
testAll!DB("oracle");
99

10+
//testArrayOutputBinding();
11+
12+
//dateTest();
13+
1014
//auto database1 = Database!()();
1115
//auto database2 = Database!()("oracle");
1216

13-
auto database3 = createDatabase();
14-
auto database4 = std.database.oracle.createDatabase();
17+
/*
18+
auto database3 = createDatabase();
19+
auto database4 = std.database.oracle.createDatabase();
20+
*/
1521

1622
//auto database = Database!DefaultPolicy.create("oracle");
1723
//auto database = Database.create("oracle");
@@ -40,7 +46,53 @@ unittest {
4046
writeResultRange(con.statement("select * from t").range());
4147
*/
4248

43-
dateTest();
49+
}
50+
51+
void testArrayOutputBinding() {
52+
// test different combinations
53+
import std.conv;
54+
import std.datetime;
55+
56+
auto db = createDatabase("oracle");
57+
auto con = db.connection();
58+
59+
60+
if (false) {
61+
con.query("drop table t1");
62+
con.query("create table t1(a integer, b integer)");
63+
for(int i = 0; i != 1000; ++i) {
64+
con.query("insert into t1 values(" ~ to!string(i) ~ "," ~ to!string(i+1) ~ ")");
65+
}
66+
}
67+
68+
TickDuration[] durations;
69+
70+
static const int N = 4;
71+
real[N] durationsUsecs;
72+
73+
foreach(i; 0..N) {
74+
auto rs = con.rowArraySize(100).query("select * from t1");
75+
StopWatch sw;
76+
sw.start();
77+
78+
int s;
79+
foreach(r;rs) {
80+
s += r[0].as!int + r[1].as!int;
81+
}
82+
83+
durations ~= sw.peek;
84+
writeln("time: ", to!Duration(sw.peek));
85+
}
86+
87+
real sum = 0;
88+
89+
foreach (TickDuration duration; durations) {
90+
real usecs = duration.usecs();
91+
sum += usecs;
92+
}
93+
94+
real avg = sum / N;
95+
writeln("avg time: ", avg);
4496
}
4597

4698
void dateTest() {

src/std/database/freetds/database.d

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ auto createDatabase()(string defaultURI="") {
3030

3131
struct Driver(Policy) {
3232
alias Allocator = Policy.Allocator;
33+
alias Cell = BasicCell!(Driver!Policy,Policy);
3334

3435
private static bool isError(RETCODE ret) {
3536
return
@@ -54,9 +55,11 @@ struct Driver(Policy) {
5455
struct Database {
5556
alias queryVariableType = QueryVariableType.QuestionMark;
5657

57-
bool bindable() {return false;}
58-
bool dateBinding() {return false;}
59-
bool poolEnable() {return false;}
58+
static const FeatureArray features = [
59+
//Feature.InputBinding,
60+
//Feature.DateBinding,
61+
//Feature.ConnectionPool,
62+
];
6063

6164
Allocator allocator;
6265

@@ -235,12 +238,12 @@ struct Driver(Policy) {
235238
private auto con() {return stmt.con;}
236239
private auto dbproc() {return con.con;}
237240

238-
this(Statement* stmt_) {
241+
this(Statement* stmt_, int rowArraySize_) {
239242
stmt = stmt_;
240243
allocator = stmt.allocator;
241244

242245
status = check("dbresults", dbresults(dbproc));
243-
if (status == NO_MORE_RESULTS) return;
246+
if (!hasResult()) return;
244247

245248
columns = dbnumcols(dbproc);
246249
info("COLUMNS:", columns);
@@ -249,7 +252,6 @@ struct Driver(Policy) {
249252

250253
build_describe();
251254
build_bind();
252-
next();
253255
}
254256

255257
~this() {
@@ -326,35 +328,35 @@ struct Driver(Policy) {
326328
}
327329
}
328330

329-
bool start() {return status == REG_ROW;}
331+
bool hasResult() {return status != NO_MORE_RESULTS;}
330332

331-
bool next() {
333+
int fetch() {
332334
status = check("dbnextrow", dbnextrow(dbproc));
333335
if (status == REG_ROW) {
334-
return true;
336+
return 1;
335337
} else if (status == NO_MORE_ROWS) {
336338
stmt.reset();
337-
return false;
339+
return 0;
338340
}
339-
return false;
341+
return 0;
340342
}
341343

342-
auto get(X:string)(Bind *b) {
344+
auto get(X:string)(Cell* cell) {
343345
import core.stdc.string: strlen;
344-
checkType(b.bindType, NTBSTRINGBIND);
345-
auto ptr = cast(immutable char*) b.data.ptr;
346+
checkType(cell.bind.bindType, NTBSTRINGBIND);
347+
auto ptr = cast(immutable char*) cell.bind.data.ptr;
346348
return cast(string) ptr[0..strlen(ptr)];
347349
}
348350

349-
auto get(X:int)(Bind *b) {
351+
auto get(X:int)(Cell* cell) {
350352
//if (b.bindType == SQL_C_CHAR) return to!int(as!string()); // tmp hack
351353
//checkType(b.bindType, SQL_C_LONG);
352354
//return *(cast(int*) b.data);
353355
return 0;
354356
}
355357

356-
auto get(X:Date)(Bind *b) {
357-
auto ptr = cast(DBDATETIME*) b.data.ptr;
358+
auto get(X:Date)(Cell* cell) {
359+
auto ptr = cast(DBDATETIME*) cell.bind.data.ptr;
358360
DBDATEREC d;
359361
check("dbdatecrack", dbdatecrack(dbproc, &d, ptr));
360362
return Date(d.year, d.month, d.day);

0 commit comments

Comments
 (0)