diff options
author | tomsmeding <hallo@tomsmeding.nl> | 2015-05-23 21:38:20 +0200 |
---|---|---|
committer | tomsmeding <hallo@tomsmeding.nl> | 2015-05-23 21:38:20 +0200 |
commit | 934e7d22b43247ebe7ec5f4990814117baab7fda (patch) | |
tree | 91e17d6b37b751f3cf9e4af035c3e4b0163bfe36 | |
parent | bd0fac9d424ccec65942c81c11b7aefe25c8a829 (diff) |
UpdateQuery finish
-rw-r--r-- | engine.cpp | 74 | ||||
-rw-r--r-- | enginedata.cpp | 2 | ||||
-rw-r--r-- | query.cpp | 9 |
3 files changed, 68 insertions, 17 deletions
@@ -44,6 +44,20 @@ int main(int argc,char **argv){ Table *hoitb=&tables.at("hoi"); + + + //Shitty. Works. +#define FINDQUERYEVERYTHING(PAR_tnm) \ + { \ + FindQuery fqu; \ + fqu.tablename= PAR_tnm ; \ + QueryResult res=fqu.execute(tables); \ + cout<<"Find in \"" PAR_tnm "\", Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; \ + for(const Row &r : res.rows)cout<<"- "<<r<<endl; \ + } + + + { Row row(3,hoitb); row.items[0].v.rh_int32=UINT_MAX; @@ -56,7 +70,7 @@ int main(int argc,char **argv){ QueryResult res=iqu.execute(tables); - cout<<"Insert [-1 uint_max \"hallo daar\"] into \"hoi\", Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; + cout<<"Insert [UINT_MAX UINT_MAX \"hallo daar\"] into \"hoi\", Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; for(const Row &r : res.rows)cout<<"- "<<r<<endl; } @@ -72,22 +86,52 @@ int main(int argc,char **argv){ QueryResult res=iqu.execute(tables); - cout<<"Insert [42 uint_max \"doei\"] into \"hoi\", Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; + cout<<"Insert [42 UINT_MAX \"doei\"] into \"hoi\", Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; for(const Row &r : res.rows)cout<<"- "<<r<<endl; } + FINDQUERYEVERYTHING("hoi") + { - FindQuery fqu; - fqu.tablename="hoi"; - RowItem ri; ri.v.rh_uint32=UINT_MAX; - fqu.where.emplace_back(1,ri); + UpdateQuery uqu; + uqu.tablename="hoi"; + + RowItem ri; + ri.v.rh_bytes=new unsigned char[10]; + memcpy(ri.v.rh_bytes,"hallo daar",10); + uqu.where.push_back({2,ri}); + + delete[] ri.v.rh_bytes; + ri.v.rh_int32=20; + uqu.updates.push_back({0,ri}); - QueryResult res=fqu.execute(tables); + QueryResult res=uqu.execute(tables); - cout<<"Find in \"hoi\" where {1}=uint_max, Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; + cout<<"Update in \"hoi\" where {2}=\"hallo daar\" {0}->20, Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; for(const Row &r : res.rows)cout<<"- "<<r<<endl; } + FINDQUERYEVERYTHING("hoi") + + { + UpdateQuery uqu; + uqu.tablename="hoi"; + + RowItem ri; + ri.v.rh_uint32=UINT_MAX; + uqu.where.push_back({1,ri}); + + ri.v.rh_uint32=12345; + uqu.updates.push_back({1,ri}); + + QueryResult res=uqu.execute(tables); + + cout<<"Update in \"hoi\" where {1}=UINT_MAX {1}->12345, Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; + for(const Row &r : res.rows)cout<<"- "<<r<<endl; + } + + FINDQUERYEVERYTHING("hoi") + { DeleteQuery dqu; dqu.tablename="hoi"; @@ -100,17 +144,19 @@ int main(int argc,char **argv){ for(const Row &r : res.rows)cout<<"- "<<r<<endl; } + FINDQUERYEVERYTHING("hoi") + { - FindQuery fqu; - fqu.tablename="hoi"; - RowItem ri; ri.v.rh_uint32=UINT_MAX; - fqu.where.emplace_back(1,ri); + DropQuery drqu; + drqu.tablename="hoi"; - QueryResult res=fqu.execute(tables); + QueryResult res=drqu.execute(tables); - cout<<"Find in \"hoi\" where {1}=uint_max, Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; + cout<<"Drop table \"hoi\", Result: "<<res.res<<": (msg=\""<<res.msg<<"\")"<<endl; for(const Row &r : res.rows)cout<<"- "<<r<<endl; } + FINDQUERYEVERYTHING("hoi") + return 0; } diff --git a/enginedata.cpp b/enginedata.cpp index 8b4d3fa..ff67f4d 100644 --- a/enginedata.cpp +++ b/enginedata.cpp @@ -91,7 +91,7 @@ int riCompare(int32_t v1,int32_t v2){return v1-v2;} int riCompare(uint32_t v1,uint32_t v2){return v1-v2;} int riCompare(unsigned char *v1,unsigned char *v2,int len){ int i; - cerr<<"Comparing "<<(void*)v1<<" ("<<v1<<") and "<<(void*)v2<<" ("<<v2<<')'<<endl; + // cerr<<"Comparing "<<(void*)v1<<" ("<<v1<<") and "<<(void*)v2<<" ("<<v2<<')'<<endl; for(i=0;i<len;i++){ if(v1[i]!=v2[i])return v1[i]-v2[i]; } @@ -120,6 +120,8 @@ QueryResult InsertQuery::execute(map <string,Table> &tables){ } +UpdateQuery::UpdateQuery(void){}; + QueryResult UpdateQuery::execute(map<string,Table> &tables){ const map<string,Table>::iterator tit=tables.find(tablename); if(tit==tables.cend())return QueryResult(0,"non-existent table (UQ:ex)"); @@ -136,11 +138,12 @@ QueryResult UpdateQuery::execute(map<string,Table> &tables){ for(i=0;i<numupdates;i++){ const int col=updates[i].col; if(col<0||col>=table.nc)return QueryResult(0,"invalid col (UQ:ex)"); + if(col==0)return QueryResult(0,"update primary key (UQ:ex)"); } for(i=0;i<(int)ret.first.size();i++){ for(j=0;j<numupdates;j++){ const int col=updates[j].col; - it->second.items[col]=updates[j].value.copy(table.header[col]); + ret.first[i]->second.items[col]=updates[j].value.copy(table.header[col]); } } return QueryResult(ret.first.size()); @@ -167,9 +170,11 @@ QueryResult DeleteQuery::execute(map<string,Table> &tables){ } +DropQuery::DropQuery(void){}; + QueryResult DropQuery::execute(map<string,Table> &tables){ const map<string,Table>::iterator tit=tables.find(tablename); - if(tit==tables.cend())return QueryResult(0,"non-existent table (DQ:ex)"); + if(tit==tables.cend())return QueryResult(0,"non-existent table (DrQ:ex)"); tables.erase(tit); return QueryResult(1); } |