int main(int argc, char **argv) { AUrl url("mysql://*****:*****@localhost/aos/"); AMySQLServer server(url); AString strError; if (!server.init(strError)) { std::cout << strError << std::endl; return -1; } else { ARope rope; AXmlElement base("base"); server.emit(base); AResultSet rs; if (server.executeSQL("SELECT * FROM global", rs, strError)) { rs.emit(base); } else base.addElement("error", strError); base.emitXml(rope, 0); std::cout << rope << std::endl; } return 0; }
void testSelect(ADatabase& db) { AString error; AResultSet rs; u4 rows = db.executeSQL("SELECT * from global", rs, error); if (AString::npos == rows) { std::cerr << error << std::endl; } else { std::cout << "Selected " << rows << " rows." << std::endl; AXmlElement root("root"); rs.emit(root); ARope rope; root.emitXml(rope, 0); std::cout << rope << std::endl; } u4 myNameCol = rs.getFieldIndex("name"); u4 myValueCol = rs.getFieldIndex("value"); for (u4 row=0; row<rs.getRowCount(); ++row) { const AString& name = rs.getData(row, myNameCol); if (name.equals("test_query")) { AQueryString qs(rs.getData(row, myValueCol)); AString str; qs.emit(str); std::cout << "Query string detected: " << str << std::endl; } else if (name.equals("flags")) { ABitArray flags(rs.getData(row, myValueCol)); AString str; flags.emit(str); std::cout << "Flags found: " << str << std::endl; str.clear(); flags.setOutputMode(ABitArray::Binary); flags.emit(str); std::cout << "Flags found: " << str << std::endl; } } }
int main(int argc, char **argv) { if (argc < 2) { std::cout << "Usage: this [SQLite database URL]" << std::endl; std::cout << "e.g. this sqlite://q:/mydata.db" << std::endl; return -1; } AUrl url(argv[1]); ASQLiteServer db(url); AString error; if (!db.init(error)) { std::cerr << error << std::endl; return -1; } AString input; AFile_IOStream iof; std::cout << "\r\nsqlite [?=help]>" << std::flush; while(AString::npos != iof.readLine(input)) { if (input.equals("createAOSTables")) { if (AString::npos == createAOSTables(db, error)) std::cerr << error << std::endl; else std::cout << "AOS tables created." << std::endl; } else if (input.equals("?")) { std::cout << "Enter SQL query or use one of the following built in functions:\r\n"; std::cout << " createAOSTables - create databases used by base AOS server modules\r\n"; std::cout << std::endl; } else if (input.equals("exit")) { return 0; } else { AResultSet rs; u4 rows = db.executeSQL(input, rs, error); if (AString::npos == rows) { std::cerr << error << std::endl; error.clear(); } else { std::cout << "Success, rows affected=" << rows << std::endl; ARope rope; rs.emit(rope); std::cout << rope << std::endl; } } input.clear(); std::cout << "\r\nsqlite>" << std::flush; } return 0; }