ligdamm: Create a table and check for table presence



Hi,
Two simple questions. What would be the best way to check for table presence in database? And how to create a table in a general way? In the first question I mean that I need to check for table in DB but that table may not contain any record. I solved this problem by getting RefPtr<DataModel> object from string
Glib::ustring sql = "SELECT TABLE_SCHEMA FROM information_schema.tables WHERE TABLE_NAME='mytable' ";
and checking
if (data_model->get_n_rows() != -1)
return true; // Table exists
else
return false; // Table doesn't exists

Is it ok to use information_schema for SQLIte3, MySQL, and PostgreSQL DB? If my solution is lame, what would be the better way to check for table availability.
More and more I think about Connection::table_exist(const Glib::ustring&). Does it make sense?

For second question, I use parser to parse sql string and pass it to Connection object. sql string is simple CREATE TABLE .......
Again, is it good approach to cover all three databases mentioned above?

Thanks.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]