diff options
author | tomsmeding <hallo@tomsmeding.nl> | 2015-05-23 20:08:33 +0200 |
---|---|---|
committer | tomsmeding <hallo@tomsmeding.nl> | 2015-05-23 20:08:33 +0200 |
commit | 91f7a1c413a8be587fdc0b357fe6412e89d16d7d (patch) | |
tree | cabf1de25549d4163be0ee2a318649e4bbfb33e7 /engine.cpp | |
parent | 0dee65740a538a2cf722d1362042aa81252b6ba5 (diff) |
Clean up main and add delete test to main
Diffstat (limited to 'engine.cpp')
-rw-r--r-- | engine.cpp | 106 |
1 files changed, 71 insertions, 35 deletions
@@ -26,55 +26,91 @@ void createTable(string name,T&&... args){ int main(int argc,char **argv){ - ColHeader *header=new ColHeader[3]; - header[0]={RH_INT32,0}; - header[1]={RH_UINT32,0}; - header[2]={RH_BYTES,10}; + { + ColHeader *header=new ColHeader[3]; + header[0]={RH_INT32,0}; + header[1]={RH_UINT32,0}; + header[2]={RH_BYTES,10}; + + CreateQuery cqu; + cqu.tablename="hoi"; + cqu.nc=3; + cqu.setHeader(header); + QueryResult res=cqu.execute(tables); + + cout<<"Create table \"hoi\", Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; + for(const Row &r : res.rows)cout<<"- "<<r<<endl; + } - CreateQuery cqu; - cqu.tablename="hoi"; - cqu.nc=3; - cqu.setHeader(header); - QueryResult res=cqu.execute(tables); + Table *hoitb=&tables.at("hoi"); - cout<<"Create, Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; - for(const Row &r : res.rows)cout<<"- "<<r<<endl; + { + Row row(3,hoitb); + row.items[0].rh_int32=UINT_MAX; + row.items[1].rh_uint32=UINT_MAX; + row.items[2].rh_bytes=new unsigned char[10]; + memcpy((char*)row.items[2].rh_bytes,"hallo daar",10); - Table *hoitb=&tables.at("hoi"); + InsertQuery iqu(move(row)); + iqu.tablename="hoi"; + + QueryResult res=iqu.execute(tables); + + cout<<"Insert [-1 uint_max \"hallo daar\"] into \"hoi\", Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; + for(const Row &r : res.rows)cout<<"- "<<r<<endl; + } + + { + Row row(3,hoitb); + row.items[0].rh_int32=42; + row.items[1].rh_uint32=UINT_MAX; + row.items[2].rh_bytes=new unsigned char[10]; + memcpy((char*)row.items[2].rh_bytes,"doei!\0\0\0\0",10); + + InsertQuery iqu(move(row)); + iqu.tablename="hoi"; - Row row(3,hoitb); - row.items[0].rh_int32=UINT_MAX; - row.items[1].rh_uint32=UINT_MAX; - row.items[2].rh_bytes=new unsigned char[10]; - memcpy((char*)row.items[2].rh_bytes,"hallo daar",10); + QueryResult res=iqu.execute(tables); - InsertQuery iqu(move(row)); - iqu.tablename="hoi"; + cout<<"Insert [42 uint_max \"doei\"] into \"hoi\", Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; + for(const Row &r : res.rows)cout<<"- "<<r<<endl; + } - res=iqu.execute(tables); + { + FindQuery fqu; + fqu.tablename="hoi"; + RowItem ri; ri.rh_uint32=UINT_MAX; + fqu.where.emplace_back(1,ri); - cout<<"Insert, Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; - for(const Row &r : res.rows)cout<<"- "<<r<<endl; + QueryResult res=fqu.execute(tables); - iqu.row.items[0].rh_int32=42; - memcpy((char*)iqu.row.items[2].rh_bytes,"doei!\0\0\0\0",10); + cout<<"Find in \"hoi\" where {1}=uint_max, Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; + for(const Row &r : res.rows)cout<<"- "<<r<<endl; + } - res=iqu.execute(tables); + { + DeleteQuery dqu; + dqu.tablename="hoi"; + RowItem ri; ri.rh_int32=-1; + dqu.where.emplace_back(0,ri); - cout<<"Insert, Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; - for(const Row &r : res.rows)cout<<"- "<<r<<endl; + QueryResult res=dqu.execute(tables); - cout<<"hoitb has "<<hoitb->rows.size()<<" row"<<(hoitb->rows.size()==1?"":"s")<<'.'<<endl; + cout<<"Delete from \"hoi\" where {0}=-1, Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; + for(const Row &r : res.rows)cout<<"- "<<r<<endl; + } - FindQuery fqu; - fqu.tablename="hoi"; - RowItem ri; ri.rh_uint32=UINT_MAX; - fqu.where.emplace_back(1,ri); + { + FindQuery fqu; + fqu.tablename="hoi"; + RowItem ri; ri.rh_uint32=UINT_MAX; + fqu.where.emplace_back(1,ri); - res=fqu.execute(tables); + QueryResult res=fqu.execute(tables); - cout<<"Find, Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; - for(const Row &r : res.rows)cout<<"- "<<r<<endl; + cout<<"Find in \"hoi\" where {1}=uint_max, Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; + for(const Row &r : res.rows)cout<<"- "<<r<<endl; + } return 0; } |