Skip to content

Commit

Permalink
better bind logic (Oracle), rowArraySize
Browse files Browse the repository at this point in the history
compile fix, Feature Flags
  • Loading branch information
cruisercoder committed May 1, 2016
1 parent ffa3999 commit f27e73b
Show file tree
Hide file tree
Showing 13 changed files with 552 additions and 256 deletions.
3 changes: 2 additions & 1 deletion mysql/test.d
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ unittest {

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

/*
void perf1() {
import std.datetime;
import std.conv;
Expand Down Expand Up @@ -69,4 +70,4 @@ void perf1() {
writeln("sum: ", sum);
writeln("time: ", to!Duration(sw2.peek));
}

*/
1 change: 1 addition & 0 deletions oracle/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
],
"sourcePaths": [".", "../src"],
"libs" : ["occi","clntsh"],
"versions": ["StdLoggerDisableLogging"],
"dependencies": {
},
"configurations": [
Expand Down
58 changes: 55 additions & 3 deletions oracle/test.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ unittest {
alias DB = Database!DefaultPolicy;
testAll!DB("oracle");

//testArrayOutputBinding();

//dateTest();

//auto database1 = Database!()();
//auto database2 = Database!()("oracle");

auto database3 = createDatabase();
auto database4 = std.database.oracle.createDatabase();
/*
auto database3 = createDatabase();
auto database4 = std.database.oracle.createDatabase();
*/

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

dateTest();
}

void testArrayOutputBinding() {
// test different combinations
import std.conv;
import std.datetime;

auto db = createDatabase("oracle");
auto con = db.connection();


if (false) {
con.query("drop table t1");
con.query("create table t1(a integer, b integer)");
for(int i = 0; i != 1000; ++i) {
con.query("insert into t1 values(" ~ to!string(i) ~ "," ~ to!string(i+1) ~ ")");
}
}

TickDuration[] durations;

static const int N = 4;
real[N] durationsUsecs;

foreach(i; 0..N) {
auto rs = con.rowArraySize(100).query("select * from t1");
StopWatch sw;
sw.start();

int s;
foreach(r;rs) {
s += r[0].as!int + r[1].as!int;
}

durations ~= sw.peek;
writeln("time: ", to!Duration(sw.peek));
}

real sum = 0;

foreach (TickDuration duration; durations) {
real usecs = duration.usecs();
sum += usecs;
}

real avg = sum / N;
writeln("avg time: ", avg);
}

void dateTest() {
Expand Down
36 changes: 19 additions & 17 deletions src/std/database/freetds/database.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ auto createDatabase()(string defaultURI="") {

struct Driver(Policy) {
alias Allocator = Policy.Allocator;
alias Cell = BasicCell!(Driver!Policy,Policy);

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

bool bindable() {return false;}
bool dateBinding() {return false;}
bool poolEnable() {return false;}
static const FeatureArray features = [
//Feature.InputBinding,
//Feature.DateBinding,
//Feature.ConnectionPool,
];

Allocator allocator;

Expand Down Expand Up @@ -235,12 +238,12 @@ struct Driver(Policy) {
private auto con() {return stmt.con;}
private auto dbproc() {return con.con;}

this(Statement* stmt_) {
this(Statement* stmt_, int rowArraySize_) {
stmt = stmt_;
allocator = stmt.allocator;

status = check("dbresults", dbresults(dbproc));
if (status == NO_MORE_RESULTS) return;
if (!hasResult()) return;

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

build_describe();
build_bind();
next();
}

~this() {
Expand Down Expand Up @@ -326,35 +328,35 @@ struct Driver(Policy) {
}
}

bool start() {return status == REG_ROW;}
bool hasResult() {return status != NO_MORE_RESULTS;}

bool next() {
int fetch() {
status = check("dbnextrow", dbnextrow(dbproc));
if (status == REG_ROW) {
return true;
return 1;
} else if (status == NO_MORE_ROWS) {
stmt.reset();
return false;
return 0;
}
return false;
return 0;
}

auto get(X:string)(Bind *b) {
auto get(X:string)(Cell* cell) {
import core.stdc.string: strlen;
checkType(b.bindType, NTBSTRINGBIND);
auto ptr = cast(immutable char*) b.data.ptr;
checkType(cell.bind.bindType, NTBSTRINGBIND);
auto ptr = cast(immutable char*) cell.bind.data.ptr;
return cast(string) ptr[0..strlen(ptr)];
}

auto get(X:int)(Bind *b) {
auto get(X:int)(Cell* cell) {
//if (b.bindType == SQL_C_CHAR) return to!int(as!string()); // tmp hack
//checkType(b.bindType, SQL_C_LONG);
//return *(cast(int*) b.data);
return 0;
}

auto get(X:Date)(Bind *b) {
auto ptr = cast(DBDATETIME*) b.data.ptr;
auto get(X:Date)(Cell* cell) {
auto ptr = cast(DBDATETIME*) cell.bind.data.ptr;
DBDATEREC d;
check("dbdatecrack", dbdatecrack(dbproc, &d, ptr));
return Date(d.year, d.month, d.day);
Expand Down
Loading

0 comments on commit f27e73b

Please sign in to comment.