Skip to content

Commit

Permalink
Add sql binary blob test. For HaxeFoundation#864
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsando committed Nov 15, 2019
1 parent 033b409 commit 0a50f68
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ test/std/arm64
test/std/cpp32
test/std/cpp64
test/std/mybase.db
test/std/hxcpp.db
test/opMatrix/Ops.hx
test/opMatrix/cpp
test/haxe/cpp
Expand All @@ -25,4 +26,4 @@ hxcpp.n
*.pdb
*.ilk

.vscode
.vscode
2 changes: 1 addition & 1 deletion src/hx/libs/sqlite/Sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ Dynamic _hx_sqlite_result_next(Dynamic handle)
case SQLITE_BLOB:
{
int size = sqlite3_column_bytes(r->r,i);
f = String::create((const char *)sqlite3_column_blob(r->r,i),size);
f = Array_obj<unsigned char>::fromData((const unsigned char *)sqlite3_column_blob(r->r,i),size);
break;
}
default:
Expand Down
25 changes: 17 additions & 8 deletions test/std/Test.hx
Original file line number Diff line number Diff line change
Expand Up @@ -104,38 +104,47 @@ class Test
v("connected :" + cnx);
if (cnx.dbName() == "SQLite") {
cnx.request("
CREATE TABLE IF NOT EXISTS User (
CREATE TABLE IF NOT EXISTS UserPwd (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
age INTEGER,
money DOUBLE
money DOUBLE,
password BLOB
)");
} else {
cnx.request("
CREATE TABLE IF NOT EXISTS User (
CREATE TABLE IF NOT EXISTS UserPwd (
id INTEGER NOT NULL AUTO_INCREMENT,
name TEXT,
age INTEGER,
money DOUBLE,
password BLOB,
PRIMARY KEY(id)
)");
}
var dels = cnx.request("DELETE FROM User");
var dels = cnx.request("DELETE FROM UserPwd");
if (dels.nfields != 0)
return error("Bad DELETE'd result");
v("deleted " + dels.length + " existing rows");

cnx.request("INSERT INTO User (name,age,money) VALUES ('John',32,100.45)");
cnx.request("INSERT INTO User (name,age,money) VALUES ('Bob',14,4.50)");
cnx.request("INSERT INTO UserPwd (name,age,money,password) VALUES ('John',32,100.45,X'c0ffee')");
cnx.request("INSERT INTO UserPwd (name,age,money,password) VALUES ('Bob',14,4.50,X'deadbeef01020304')");

var rset = cnx.request("SELECT * FROM User");
var rset = cnx.request("SELECT * FROM UserPwd");

var length = rset.length;
v("found "+length+" users");
if (length!=2)
return error("Bad user count");
for( row in rset )
v(" user "+row.name+" is "+row.age+" years old ");
{
var pass:Dynamic = row.password;
var password = Std.is(pass, haxe.io.BytesData) ? haxe.io.Bytes.ofData(pass) : pass;
var md5 = haxe.crypto.Md5.make(password).toHex().substr(0,8);
v(" user "+row.name+" is "+row.age+" years old, password:" + md5);
if (md5!="5f80e231" && md5!="8ed0b363")
return error("Bad binary blob store");
}
return 0;
}

Expand Down

0 comments on commit 0a50f68

Please sign in to comment.