A C++ DAL / ORM code generation framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.4 KiB

12 years ago
12 years ago
12 years ago
  1. #include "../src/sql/wsqldatabase.h"
  2. #include <iostream>
  3. int main()
  4. {
  5. WSql::WSqlDatabase db(WSql::WSQLITE);
  6. db.setDatabaseName(std::string("blog.db"));
  7. if (!db.open()) {
  8. std::cerr << "Failed to open: " << db.error().text() << std::endl;
  9. return 1;
  10. }
  11. std::vector<std::string>tables = db.tableNames();
  12. std::vector<std::string>::iterator it = tables.begin();
  13. WSql::WSqlTable stbl;
  14. int numflds = 0;
  15. int col = 0;
  16. while (it != tables.end())
  17. {
  18. stbl = db.tableMetaData(*it++);
  19. numflds = stbl.count();
  20. std::cout << " ======== Table name: " << stbl.name()
  21. << " =========" << std::endl;
  22. for (col=0; col < numflds; ++col)
  23. {
  24. WSql::WSqlColumn clm = stbl.column(col);
  25. std::cout << "Column " << col << " = " << clm.columnName() << std::endl;
  26. std::cout << " * type: " << WSql::WSqlDataType::toString(clm.dataType()) << std::endl;
  27. std::cout << " * can be null: " << (clm.canBeNull() ? "true" : "false") << std::endl;
  28. std::cout << " * primary key: " << (clm.isPrimaryKey() ? "true" : "false") << std::endl;
  29. std::cout << " * default: " << clm.defaultValue<std::string>() << std::endl;
  30. std::cout << " * Autoincrement: " << (clm.isAutoIncremented()?"true" : "false") << std::endl;
  31. }
  32. }
  33. }