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.

36 lines
1.2 KiB

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