#include <libgda/libgda.h>

GdaConnection* conn = NULL;


int main()
{
  gda_init();

  GError* error = NULL;
  conn = gda_connection_open_from_string("PostgreSQL",
    "HOST=localhost;PORT=5433;DB_NAME=glom_example_smallbusiness_v2",
    "USERNAME=testuser;PASSWORD=testpw",
    GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE,
    &error);
  
  if (error) {
    g_warning("gda_connection_open_from_string() failed: %s\n", error->message);
    g_clear_error(&error);
    return 0;
  }
  
  gda_connection_update_meta_store(conn, NULL, &error);
  if (error) {
    g_warning("gda_connection_update_meta_store() failed: %s\n", error->message);
    g_clear_error(&error);
    return 0;
  }
  
  GdaDataModel* model = gda_connection_get_meta_store_data(conn,
    GDA_CONNECTION_META_TABLES,
    &error, 
    0);
  if (error) {
    g_warning("gda_connection_get_meta_store_data() failed: %s\n", error->message);
    g_clear_error(&error);
    return 0;
  }

  if (!model) {
    g_warning("gda_connection_get_meta_store_data() returned a null GdaDataModel.");
    g_clear_error(&error);
    return 0;
  }
  
  if (gda_data_model_get_n_columns(model) <= 0) {
    g_warning("gda_connection_get_meta_store_data() returned no GdaDataModel columns.");
    g_clear_error(&error);
    return 0;
  }
  
  //Here is the problem:
  //No rows are returned but there is no error, or other clue, either.
  if (gda_data_model_get_n_rows(model) <= 0) {
    g_warning("gda_connection_get_meta_store_data() returned no GdaDataModel rows.");
    g_clear_error(&error);
    return 0;
  }  
  
  gda_connection_close(conn);

  return 0;
}
