aboutsummaryrefslogtreecommitdiff
path: root/query.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'query.cpp')
-rw-r--r--query.cpp44
1 files changed, 29 insertions, 15 deletions
diff --git a/query.cpp b/query.cpp
index b88fbd8..5d2e3fd 100644
--- a/query.cpp
+++ b/query.cpp
@@ -4,8 +4,11 @@
using namespace std;
-ColValueClause::ColValueClause(void):col(0){}
-ColValueClause::ColValueClause(const int _c,const RowItem &_v):col(_c),value(_v){}
+WhereClause::WhereClause(void):col(0){}
+WhereClause::WhereClause(const int _c,const vector<RowItem> &_v):col(_c),values(_v){}
+
+UpdateClause::UpdateClause(void):col(0){}
+UpdateClause::UpdateClause(const int _c,const RowItem &_v):col(_c),value(_v){}
QueryResult::QueryResult(void):res(0){}
@@ -16,6 +19,7 @@ QueryResult::QueryResult(int _res,const string &_m):res(_res),msg(_m){}
QueryResult Query::execute(map<string,Table> &tables){return QueryResult(-1);}
+Query::~Query(void){}
CreateQuery::CreateQuery(void):nc(0),header(NULL){}
@@ -47,24 +51,31 @@ pair<vector<map<string,Row>::const_iterator>,string> FindQuery::executeIterators
pair<vector<map<string,Row>::const_iterator>,string> FindQuery::executeIterators(const Table &table){
if(limit==0)return {{},"zero limit (FQ:eI)"};
- int i,j;
+ int i,j,k;
for(i=0;i<(int)where.size();i++){
if(where[i].col==0)break;
}
if(i!=(int)where.size()){
- const map<string,Row>::const_iterator rit=table.rows.find(serialise(table.header[0],where[i].value));
- if(rit==table.rows.end())return {{},""};
- const Row &row=rit->second;
- for(j=0;j<(int)where.size();j++){
- if(j==i)continue;
- const int col=where[j].col;
- if(riCompare(table.header[col],row.items[col],where[j].value)!=0)break;
+ for(const RowItem &wh : where[i].values){
+ const map<string,Row>::const_iterator rit=table.rows.find(serialise(table.header[0],wh));
+ if(rit==table.rows.end())return {{},""};
+ const Row &row=rit->second;
+ for(j=0;j<(int)where.size();j++){
+ if(j==i)continue;
+ const int col=where[j].col;
+ if(col<0||col>=table.nc){
+ return {{},"invalid col (DQ:eI)"};
+ }
+ for(k=0;k<where[j].values.size();k++){
+ if(riCompare(table.header[col],row.items[col],where[j].values[k])==0)break;
+ }
+ if(k==where[j].values.size())return {{},""};
+ }
+ vector<map<string,Row>::const_iterator> v;
+ v.push_back(rit);
+ return {v,""};
}
- if(j!=(int)where.size())return {{},""};
- vector<map<string,Row>::const_iterator> v;
- v.push_back(rit);
- return {v,""};
}
typedef map<string,Row>::const_iterator cit_t;
@@ -81,7 +92,10 @@ pair<vector<map<string,Row>::const_iterator>,string> FindQuery::executeIterators
for(cit_t it=table.rows.begin();it!=end;it++){
for(i=0;i<(int)where.size();i++){
const int col=where[i].col;
- if(riCompare(table.header[col],it->second.items[col],where[i].value)!=0)break;
+ for(j=0;j<where[i].values.size();j++){
+ if(riCompare(table.header[col],it->second.items[col],where[i].values[j])==0)break;
+ }
+ if(j==where[i].values.size())break;
}
if(i==(int)where.size()){
ret.first.push_back(it);