/* Build with:
 * gcc libgda_sqlite_createtable.c `pkg-config libgda-5.0 --cflags --libs`
 */

#include <libgda/libgda.h>

GdaConnection* create_database()
{
	GdaServerOperation* op = gda_server_operation_prepare_create_database("SQLite", "test_db", NULL);
	gda_server_operation_perform_create_database(op, "SQLite", NULL);

	GdaConnection* connection = gda_connection_open_from_string("SQLite", "DB_NAME=test_db", NULL, 0, NULL);
	return connection;
}

int main()
{
	gda_init();

	GdaConnection* connection;
	if(!g_file_test("test_db.db", G_FILE_TEST_IS_REGULAR))
		connection = create_database();
	else
		connection = gda_connection_open_from_string("SQLite", "DB_NAME=test_db", NULL, 0, NULL);

	if(!connection)
	{
	  g_warning("Connection failed\n");
	  return EXIT_FAILURE;
	}
 
	const char* sql_query =
	  "CREATE TABLE \"test_table\" (\"test_id\" numeric, \"name\" varchar)";
	g_printf("SQL query: %s\n", sql_query);
	  
	const int rows_affected = 
	  gda_connection_execute_non_select_command(connection, sql_query, NULL);
	
  g_printf("rows_affected=%d\n", rows_affected);

	gda_connection_close(connection);
	
	return EXIT_SUCCESS;
}
