Add commands: limit, insertinto, update, deletefrom. Fix all update commands channel

queue v0.3_beta
marcelb 1 year ago
parent 5482d71558
commit 6c1d9c456d
  1. 9
      lib/mysql.hpp
  2. 28
      src/mysql.cpp
  3. 21
      test/test.cpp
  4. BIN
      test/test.o

@ -42,16 +42,15 @@ class sqlQA {
sqlQA& select(const string _select = "*");
sqlQA& from(const string _tablename);
sqlQA& where(const string _condition);
// sqlQA& limit();
// sqlQA& insertInTo(string _tablename, string _columns);
// sqlQA& values(); // proizvoljan broj argumenata
sqlQA& limit(const uint _limit);
sqlQA& insertInTo(const string _tablename, const string _columns = "");
sqlQA& values(const string _values);
sqlQA& update(const string _tablename);
sqlQA& set(const string _column_value_pairs);
// sqlQA& deleteFrom();
sqlQA& deleteFrom(const string _table);
// answer methods
private:
void parse_columns(const string _cloumns);
};

@ -20,6 +20,28 @@ sqlQA& sqlQA::where(const string _condition) {
return *this;
}
sqlQA& sqlQA::limit(const uint _limit) {
cmd += "LIMIT " + to_string(_limit) + " ";
return *this;
}
sqlQA& sqlQA::insertInTo(const string _tablename, const string _columns) {
isUpdate = true;
cmd += "INSERT INTO " + _tablename;
if (_columns.empty()) {
cmd += " ";
}
else {
cmd += " (" + _columns + ") ";
}
return *this;
}
sqlQA& sqlQA::values(const string _values) {
cmd += "VALUES (" + _values + ") ";
return *this;
}
sqlQA& sqlQA::update(const string _table) {
isUpdate = true;
cmd += "UPDATE " + _table + " ";
@ -31,6 +53,12 @@ sqlQA& sqlQA::set(const string _column_value_pairs) {
return *this;
}
sqlQA& sqlQA::deleteFrom(const string _table) {
isUpdate = true;
cmd += "DELETE FROM " + _table + " ";
return *this;
}
void sqlQA::parse_columns(const string _columns) {
istringstream iss(_columns);

@ -12,7 +12,7 @@ int main() {
sqlQA test_qa;
// id,user_id,zone_id,domain,record_type,auth_key,last_update,enabled
// test_qa.select().from("records").where("enabled = 1");
// test_qa.select().from("records").where("enabled = 0").limit(2);
// mydb.exec(test_qa);
// for (auto i : test_qa.result) {
@ -22,13 +22,22 @@ int main() {
// }
test_qa.update("records").set("enabled = 1").where("domain = 'bitelex.test'");
// test_qa.update("records").set("enabled = 1").where("domain = 'bitelex.test'");
// mydb.exec(test_qa);
// if (test_qa.executed) {
// cout << "Num rows affect " << test_qa.updateCatch << endl;
// }
// cout << "Num rows " << test_qa.num_rows << " num columns " << test_qa.num_columns << " executed " << test_qa.executed << endl;
// test_qa.insertInTo("records", "id,user_id,zone_id,domain,record_type,auth_key,last_update,enabled").values("'5',2,2,'www.bitelex.test','AAAA','jebiga',NULL,1");
test_qa.deleteFrom("records").where("record_type = AAAA");
// test_qa.update("records").set("enabled = 0").where("record_type = 'AAAA'");
cout << test_qa.cmd << endl;
mydb.exec(test_qa);
if (test_qa.executed) {
cout << "Num rows affect " << test_qa.updateCatch << endl;
}
cout << "Num rows " << test_qa.num_rows << " num columns " << test_qa.num_columns << " catch " << test_qa.updateCatch << " executed " << test_qa.executed << endl;
cout << "Num rows " << test_qa.num_rows << " num columns " << test_qa.num_columns << " executed " << test_qa.executed << endl;
}

Binary file not shown.
Loading…
Cancel
Save