@@ -248,28 +248,79 @@ WsjcppSqlInsert::WsjcppSqlInsert(const std::string &tableName, WsjcppSqlBuilder
248248
249249}
250250
251+ WsjcppSqlInsert &WsjcppSqlInsert::colum (const std::string &col) {
252+ m_columns.push_back (col);
253+ return *this ;
254+ }
255+
256+ WsjcppSqlInsert &WsjcppSqlInsert::addColums (const std::vector<std::string> &cols) {
257+ for (auto col : cols) {
258+ m_columns.push_back (col);
259+ }
260+ return *this ;
261+ }
262+
263+ WsjcppSqlInsert &WsjcppSqlInsert::val (const std::string &val) {
264+ m_values.push_back (WsjcppSqlBuilderHelpers::escapingStringValue (val));
265+ return *this ;
266+ }
267+
268+ WsjcppSqlInsert &WsjcppSqlInsert::val (int val) {
269+ m_values.push_back (std::to_string (val));
270+ return *this ;
271+ }
272+
273+ WsjcppSqlInsert &WsjcppSqlInsert::val (float val) {
274+ m_values.push_back (std::to_string (val));
275+ return *this ;
276+ }
277+
278+ WsjcppSqlInsert &WsjcppSqlInsert::val (double val) {
279+ m_values.push_back (std::to_string (val));
280+ return *this ;
281+ }
251282
252283std::string WsjcppSqlInsert::sql () {
253284 std::string ret = " INSERT INTO " + tableName ();
254285
286+ // TODO if columns is empty
287+ ret += " (" ;
288+ bool first = true ;
289+ for (auto col : m_columns) {
290+ if (!first) {
291+ ret += " , " ;
292+ }
293+ ret += col;
294+ first = false ;
295+ }
296+ ret += " )" ;
297+
298+ ret += " VALUES(" ;
299+ first = true ;
300+ for (auto val : m_values) {
301+ if (!first) {
302+ ret += " , " ;
303+ }
304+ ret += val;
305+ first = false ;
306+ }
307+ ret += " )" ;
308+
255309 return ret;
256310};
257311
258312// ---------------------------------------------------------------------
259313// WsjcppSqlBuilder
260314
261315WsjcppSqlSelect &WsjcppSqlBuilder::selectFrom (const std::string &tableName) {
262- m_tableName = tableName;
263- m_nSqlType = WsjcppSqlQueryType::SELECT;
264- m_queries.push_back (std::make_shared<WsjcppSqlSelect>(m_tableName, this ));
316+ m_queries.push_back (std::make_shared<WsjcppSqlSelect>(tableName, this ));
265317 // TODO check must be select last one;
266318 return *(WsjcppSqlSelect *)(m_queries[m_queries.size () -1 ].get ());
267319}
268320
269- WsjcppSqlBuilder &WsjcppSqlBuilder::insertInto (const std::string &tableName) {
270- m_tableName = tableName;
271- m_nSqlType = WsjcppSqlQueryType::INSERT;
272- return *this ;
321+ WsjcppSqlInsert &WsjcppSqlBuilder::insertInto (const std::string &tableName) {
322+ m_queries.push_back (std::make_shared<WsjcppSqlInsert>(tableName, this ));
323+ return *(WsjcppSqlInsert *)(m_queries[m_queries.size () -1 ].get ());;
273324}
274325
275326// WsjcppSqlBuilder &WsjcppSqlBuilder::makeUpdate(const std::string &tableName) {
0 commit comments