SelectQuery selectObjectQuery(const std::vector<FieldType>& fdatas, const Expr& e) { SelectQuery sel; Split tables; std::set<LITESQL_String> tableSet; for (size_t i = 0; i < fdatas.size(); i++) if (tableSet.find(fdatas[i].table()) == tableSet.end()) { tables.push_back(fdatas[i].table()); tableSet.insert(fdatas[i].table()); } Split tableFilters; tableFilters.resize(tables.size()-1); for (size_t i = 1; i < tables.size(); i++) tableFilters[i-1] = tables[i-1] + LITESQL_L(".id_ = ") + tables[i] + LITESQL_L(".id_"); tableSet.clear(); for (size_t i = 0; i < tables.size(); i++) { sel.source(tables[i]); tableSet.insert(tables[i]); } if (tables.size() > 1) sel.where((e && RawExpr(tableFilters.join(LITESQL_L(" AND ")))).asString()); else sel.where(e.asString()); for (size_t i = 0; i < fdatas.size(); i++) sel.result(fdatas[i].table() + LITESQL_L(".") + fdatas[i].name()); return sel; }
LITESQL_String Time::asString(LITESQL_String format) const { if (format == LITESQL_L("%u")) { LITESQL_Char buf[32]; snprintf(buf, 32, LITESQL_L("%d"), value); return buf; } Split data(format, LITESQL_L("%")); LITESQL_String res = data[0]; for (size_t i = 1; i < data.size(); i++) { LITESQL_String rest = data[i].substr(1, data[i].size()); switch(data[i][0]) { case 'h': res += toString(hour()) + rest; break; case 'M': if (min() < 10) res += LITESQL_L("0"); res += toString(min()) + rest; break; case 's': if (sec() < 10) res += LITESQL_L("0"); res += toString(sec()) + rest; } } return res; }
UpdateQuery::operator LITESQL_String() const { LITESQL_String q = LITESQL_L("UPDATE ") + table + LITESQL_L(" SET "); Split sets; for (size_t i = 0; i < fields.size(); i++) sets.push_back(fields[i] + LITESQL_L("=") + values[i]); q += sets.join(LITESQL_L(",")); if (_where.size()) q += LITESQL_L(" WHERE ") + _where; return q; }
LITESQL_String Persistent::insert(Record& tables, Records& fieldRecs, Records& values, const LITESQL_String& sequence) { if (values[0][0] == LITESQL_L("0")) for(size_t i = 0; i < values.size(); i++) values[i][0] = LITESQL_L("NULL"); LITESQL_String key = db->groupInsert(tables, fieldRecs, values, sequence); oldKey = atoi(key); inDatabase = true; return key; }
MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size, long type): wxDocMDIParentFrame(manager, frame, wxID_ANY, title, pos, size, type, _T(LITESQL_L("myFrame"))) { editMenu = (wxMenu *) NULL; //// Make a menubar wxMenu *file_menu = new wxMenu; wxMenu *edit_menu = (wxMenu *) NULL; file_menu->Append(wxID_NEW, _T(LITESQL_L("&New...\tCtrl-N"))); file_menu->Append(wxID_OPEN, _T(LITESQL_L("&Open...\tCtrl-X"))); file_menu->AppendSeparator(); file_menu->Append(wxID_EXIT, _T(LITESQL_L("E&xit\tAlt-X"))); // A nice touch: a history of files visited. Use this menu. m_docManager->FileHistoryUseMenu(file_menu); wxMenu *help_menu = new wxMenu; help_menu->Append(VisualLitesqlApp::ID_ABOUT, _T(LITESQL_L("&About\tF1"))); wxMenuBar *menu_bar = new wxMenuBar; menu_bar->Append(file_menu, _T(LITESQL_L("&File"))); if (edit_menu) menu_bar->Append(edit_menu, _T(LITESQL_L("&Edit"))); menu_bar->Append(help_menu, _T(LITESQL_L("&Help"))); SetMenuBar(menu_bar); }
void Persistent::update(Updates& updates) { for (Updates::iterator i = updates.begin(); i != updates.end(); i++) { UpdateQuery uq(i->first); uq.where(RawExpr(LITESQL_L("id_ = '") + toString(oldKey) + LITESQL_L("'"))); bool notEmpty = false; for (std::vector<std::pair<FieldType, LITESQL_String> >::iterator i2 = i->second.begin(); i2 != i->second.end(); i2++) { uq.set(i2->first, i2->second); notEmpty = true; } if (notEmpty) db->query(uq); } }
namespace litesql { const LITESQL_Char* Expr::True =LITESQL_L("True"); In::In(const FieldType & fld, const SelectQuery& s) : Oper(fld, LITESQL_L("in"), LITESQL_L("(") + s.asString() + LITESQL_L(")")) {} And operator&&(const Expr &o1, const Expr &o2) { return And(o1,o2); } Or operator||(const Expr &o1, const Expr &o2) { return Or(o1,o2); } Not operator!(const Expr & exp) { return Not(exp); } Eq operator==(const FieldType& fld, const FieldType& f2) { return Eq(fld, f2); } Gt operator>(const FieldType& fld, const FieldType& o2) { return Gt(fld, o2); } GtEq operator>=(const FieldType& fld, const FieldType& o2) { return GtEq(fld, o2); } Lt operator<(const FieldType& fld, const FieldType& o2) { return Lt(fld, o2); } LtEq operator<=(const FieldType& fld, const FieldType& o2) { return LtEq(fld, o2); } NotEq operator!=(const FieldType& fld, const FieldType& f2) { return NotEq(fld, f2); } }
LITESQL_String escapeSQL(const LITESQL_String &str) { LITESQL_String tmp; if (str == LITESQL_L("NULL")) return LITESQL_L("NULL"); tmp = replace(str, LITESQL_L("'NULL'"), LITESQL_L("NULL")); return LITESQL_L("'") + replace(tmp, LITESQL_L("'"), LITESQL_L("''")) + LITESQL_L("'"); }
LITESQL_String DateTime::asString(LITESQL_String format) const { if (format == LITESQL_L("%u")) { LITESQL_Char buf[32]; snprintf(buf, 32, LITESQL_L("%lu"), value); return buf; } Split data(format, LITESQL_L("%")); TimeStruct ts(value); LITESQL_String res = data[0]; for (size_t i = 1; i < data.size(); i++) { LITESQL_String rest = data[i].substr(1, data[i].size()); switch(data[i][0]) { case 'd': res += toString(ts.day()) + rest; break; case 'm': res += toString(ts.month()) + rest; break; case 'y': res += toString(ts.year()) + rest; break; case 'h': res += toString(ts.hour()) + rest; break; case 'M': if (ts.min() < 10) res += LITESQL_L("0"); res += toString(ts.min()) + rest; break; case 's': if (ts.sec() < 10) res += LITESQL_L("0"); res += toString(ts.sec()) + rest; break; } } return res; }
GraphvizGenerator(): CodeGenerator(LITESQL_L("graphviz")) { };
RubyMigrationsGenerator(): CodeGenerator(LITESQL_L("ruby-activerecord-migrations")) { };
CppGenerator(): CodeGenerator(LITESQL_L("c++")) { };
LITESQL_String fullName() const { return table() + LITESQL_L(".") + name(); }
XmlGenerator(): CodeGenerator(LITESQL_L("xml")) { };
In::In(const FieldType & fld, const SelectQuery& s) : Oper(fld, LITESQL_L("in"), LITESQL_L("(") + s.asString() + LITESQL_L(")")) {}
void Persistent::deleteFromTable(LITESQL_String table, LITESQL_String id) { db->query(LITESQL_L("DELETE FROM ") + table + LITESQL_L(" WHERE id_=")+escapeSQL(id)); }
ActiveRecordClassGenerator(): CodeGenerator(LITESQL_L("ruby-activerecord-class")) { };