[libgda: 11/17] TEST: Initial test for DDL operation for SQLite
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda: 11/17] TEST: Initial test for DDL operation for SQLite
- Date: Mon, 25 Nov 2019 18:23:03 +0000 (UTC)
commit ede080068b6e63eec8ce18676239b2cb0ac08479
Author: Pavlo Solntsev <p sun fun gmail com>
Date: Thu Mar 21 08:36:48 2019 -0500
TEST: Initial test for DDL operation for SQLite
DDL operation test was added for GdaServerOperation and GdaDB...
modules.
tests/test-server-operation-sqlite.c | 628 +++++++++++++++++------------------
1 file changed, 306 insertions(+), 322 deletions(-)
---
diff --git a/tests/test-server-operation-sqlite.c b/tests/test-server-operation-sqlite.c
index ade206bb4..b08e6034f 100644
--- a/tests/test-server-operation-sqlite.c
+++ b/tests/test-server-operation-sqlite.c
@@ -18,9 +18,7 @@
* Boston, MA 02110-1301, USA.
*/
-/* To initiate this test a variable SQLITE_SO_DDL shoule be set with value idential to the
- * connection string:
- * SQLITE_SO_DDL="DB_NAME=mydbname;DB_DIR=/some/place/with/database"
+/*
* Two tables will be created:
*
* Project
@@ -33,83 +31,43 @@
*
* An additional column "cost" will be added via ADD_COLUMN operation to the table Project
*
+ * Employee table will be renamed to NewEmployee
+ *
*/
-
#include <glib.h>
#include <glib/gi18n.h>
#include <locale.h>
#include <libgda/libgda.h>
#define PROVIDER_NAME "SQLite"
-
-typedef struct {
- gchar *prefix;
- GdaServerOperation *op;
-} QuarkSet;
+#define DB_TEST_BASE "sqlite_ddl_so_test"
+static int db_increment = 1;
typedef struct
{
GdaConnection *cnc;
- const gchar *cnc_string;
GdaServerProvider *provider;
- GdaServerOperation *op;
- gboolean skiptest;
} TestObjectFixture;
-
-static void
-set_val_quark_foreach_func (gchar *name, gchar *value, QuarkSet *setval)
-{
- gda_server_operation_set_value_at (setval->op, value, NULL, "/%s/%s", setval->prefix, name);
-}
-
static void
test_server_operation_start (TestObjectFixture *fixture,
- gconstpointer user_data)
+ gconstpointer *user_data)
{
fixture->cnc = NULL;
fixture->provider = NULL;
- fixture->op = NULL;
-
- fixture->cnc_string = g_getenv("SQLITE_SO_DDL");
-
- if (!fixture->cnc_string)
- {
- g_print ("Please set SQLITE_CREATE_DB variable"
- "with DB_DIR and DB_NAME");
- g_print ("Test will not be performed\n");
- fixture->skiptest = TRUE;
- return;
- }
-}
-
-static void
-test_server_operation_operations_start (TestObjectFixture *fixture,
- gconstpointer user_data)
-{
- fixture->cnc = NULL;
- fixture->provider = NULL;
- fixture->op = NULL;
-
- fixture->cnc_string = g_getenv("SQLITE_SO_DDL");
-
- if (!fixture->cnc_string)
- {
- g_print ("Please set SQLITE_CREATE_DB variable"
- "with DB_DIR and DB_NAME");
- g_print ("Test will not be performed\n");
- fixture->skiptest = TRUE;
- return;
- }
+ gchar *dbname = g_strdup_printf("DB_DIR=.;DB_NAME=%s_%d", DB_TEST_BASE, db_increment++);
fixture->cnc = gda_connection_open_from_string (PROVIDER_NAME,
- fixture->cnc_string,
+ dbname,
NULL,
GDA_CONNECTION_OPTIONS_NONE,
NULL);
+
g_assert_nonnull (fixture->cnc);
+ g_free (dbname);
+
fixture->provider = gda_connection_get_provider (fixture->cnc);
g_assert_nonnull (fixture->provider);
@@ -117,82 +75,27 @@ test_server_operation_operations_start (TestObjectFixture *fixture,
static void
test_server_operation_finish (TestObjectFixture *fixture,
- gconstpointer user_data)
-{
- gboolean res = gda_connection_close (fixture->cnc, NULL);
-
- g_assert_true (res);
-
- g_object_unref (fixture->cnc);
- g_object_unref (fixture->op);
-}
-
-static void
-test_server_operation_operations_finish (TestObjectFixture *fixture,
- gconstpointer user_data)
+ gconstpointer *user_data)
{
gboolean res = gda_connection_close (fixture->cnc, NULL);
g_assert_true (res);
-
- g_object_unref (fixture->op);
- g_object_unref (fixture->cnc);
-}
-static void
-test_server_operation_create_db (TestObjectFixture *fixture,
- gconstpointer user_data)
-{
- fixture->cnc = gda_connection_open_from_string (PROVIDER_NAME, fixture->cnc_string, NULL,
- GDA_CONNECTION_OPTIONS_NONE, NULL);
- g_assert_nonnull (fixture->cnc);
-
- fixture->provider = gda_connection_get_provider (fixture->cnc);
-
- g_assert_nonnull (fixture->provider);
-
- fixture->op = gda_server_provider_create_operation (fixture->provider,
- fixture->cnc,
- GDA_SERVER_OPERATION_CREATE_DB,
- NULL,
- NULL);
-
- g_assert_nonnull (fixture->op);
-
- GdaQuarkList *db_quark_list = NULL;
- db_quark_list = gda_quark_list_new_from_string (fixture->cnc_string);
-
- QuarkSet setval;
-
- setval.prefix = g_strdup ("DB_DEF_P");
- setval.op = fixture->op;
-
- gda_quark_list_foreach (db_quark_list, (GHFunc) set_val_quark_foreach_func, &setval);
-
- g_free (setval.prefix);
-
- gboolean res = gda_server_provider_perform_operation (fixture->provider,
- fixture->cnc,
- fixture->op,
- NULL);
-
- g_assert_true (res);
}
static void
test_server_operation_operations (TestObjectFixture *fixture,
gconstpointer user_data)
{
- if (fixture->skiptest)
- return;
+ GdaServerOperation *op = NULL;
/* CREATE_TABLE operation */
- fixture->op = gda_server_provider_create_operation (fixture->provider,
- fixture->cnc,
- GDA_SERVER_OPERATION_CREATE_TABLE,
- NULL,
- NULL);
+ op = gda_server_provider_create_operation (fixture->provider,
+ fixture->cnc,
+ GDA_SERVER_OPERATION_CREATE_TABLE,
+ NULL,
+ NULL);
- g_assert_nonnull (fixture->op);
+ g_assert_nonnull (op);
/* We will create two tables: Employee and Project. One table will contain foreigh key that points
* to the column from the second one.
@@ -201,7 +104,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
gboolean res = FALSE;
/* Define table name */
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"Project",
NULL,
"/TABLE_DEF_P/TABLE_NAME");
@@ -209,7 +112,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
/* Table will not be temporary */
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"FALSE",
NULL,
"/TABLE_DEF_P/TABLE_TEMP");
@@ -217,7 +120,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
/* Create table if table doesn't exist yet */
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/TABLE_DEF_P/TABLE_IFNOTEXISTS");
@@ -225,7 +128,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
/* Define column id*/
gint column_order = 0;
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"id",
NULL,
"/FIELDS_A/@COLUMN_NAME/%d",
@@ -233,7 +136,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"gint",
NULL,
"/FIELDS_A/@COLUMN_TYPE/%d",
@@ -241,7 +144,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/FIELDS_A/@COLUMN_NNUL/%d",
@@ -249,7 +152,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/FIELDS_A/@COLUMN_AUTOINC/%d",
@@ -257,7 +160,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/FIELDS_A/@COLUMN_UNIQUE/%d",
@@ -265,7 +168,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/FIELDS_A/@COLUMN_PKEY/%d",
@@ -275,7 +178,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
/* Define column name */
column_order++;
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"name",
NULL,
"/FIELDS_A/@COLUMN_NAME/%d",
@@ -283,7 +186,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"gchararray",
NULL,
"/FIELDS_A/@COLUMN_TYPE/%d",
@@ -291,14 +194,14 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"50",
NULL,
"/FIELDS_A/@COLUMN_SIZE/%d",
column_order);
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/FIELDS_A/@COLUMN_NNUL/%d",
@@ -306,7 +209,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"FALSE",
NULL,
"/FIELDS_A/@COLUMN_AUTOINC/%d",
@@ -314,7 +217,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/FIELDS_A/@COLUMN_UNIQUE/%d",
@@ -322,7 +225,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"FALSE",
NULL,
"/FIELDS_A/@COLUMN_PKEY/%d",
@@ -330,7 +233,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"Default_name",
NULL,
"/FIELDS_A/@COLUMN_DEFAULT/%d",
@@ -340,29 +243,27 @@ test_server_operation_operations (TestObjectFixture *fixture,
res = gda_server_provider_perform_operation (fixture->provider,
fixture->cnc,
- fixture->op,
+ op,
NULL);
g_assert_true (res);
- g_clear_object (&fixture->op);
+ g_clear_object (&op);
- fixture->op = gda_server_provider_create_operation (fixture->provider,
- fixture->cnc,
- GDA_SERVER_OPERATION_CREATE_TABLE,
- NULL,
- NULL);
+ op = gda_server_provider_create_operation (fixture->provider,
+ fixture->cnc,
+ GDA_SERVER_OPERATION_CREATE_TABLE,
+ NULL,
+ NULL);
- g_assert_nonnull (fixture->op);
+ g_assert_nonnull (op);
/* We will create two tables: Employee and Project. One table will contain foreigh key that points
* to the column from the second one.
*
*/
-
- res = FALSE;
/* Define table name */
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"Employee",
NULL,
"/TABLE_DEF_P/TABLE_NAME");
@@ -370,7 +271,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
/* Table will not be temporary */
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"FALSE",
NULL,
"/TABLE_DEF_P/TABLE_TEMP");
@@ -378,7 +279,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
/* Create table if table doesn't exist yet */
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/TABLE_DEF_P/TABLE_IFNOTEXISTS");
@@ -386,7 +287,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
/* Define column id */
column_order = 0;
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"id",
NULL,
"/FIELDS_A/@COLUMN_NAME/%d",
@@ -394,7 +295,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"gint",
NULL,
"/FIELDS_A/@COLUMN_TYPE/%d",
@@ -402,7 +303,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/FIELDS_A/@COLUMN_NNUL/%d",
@@ -410,7 +311,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/FIELDS_A/@COLUMN_AUTOINC/%d",
@@ -418,7 +319,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/FIELDS_A/@COLUMN_UNIQUE/%d",
@@ -426,7 +327,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/FIELDS_A/@COLUMN_PKEY/%d",
@@ -436,7 +337,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
/* Define column name */
column_order++;
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"name",
NULL,
"/FIELDS_A/@COLUMN_NAME/%d",
@@ -444,7 +345,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"gchararray",
NULL,
"/FIELDS_A/@COLUMN_TYPE/%d",
@@ -452,14 +353,14 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"50",
NULL,
"/FIELDS_A/@COLUMN_SIZE/%d",
column_order);
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/FIELDS_A/@COLUMN_NNUL/%d",
@@ -467,7 +368,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"FALSE",
NULL,
"/FIELDS_A/@COLUMN_AUTOINC/%d",
@@ -475,7 +376,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/FIELDS_A/@COLUMN_UNIQUE/%d",
@@ -483,7 +384,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"FALSE",
NULL,
"/FIELDS_A/@COLUMN_PKEY/%d",
@@ -491,7 +392,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"Default_name",
NULL,
"/FIELDS_A/@COLUMN_DEFAULT/%d",
@@ -501,7 +402,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
/* Define column project_id */
column_order++;
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"project_id",
NULL,
"/FIELDS_A/@COLUMN_NAME/%d",
@@ -509,7 +410,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"gint",
NULL,
"/FIELDS_A/@COLUMN_TYPE/%d",
@@ -517,7 +418,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/FIELDS_A/@COLUMN_NNUL/%d",
@@ -525,7 +426,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"FALSE",
NULL,
"/FIELDS_A/@COLUMN_AUTOINC/%d",
@@ -533,7 +434,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"FALSE",
NULL,
"/FIELDS_A/@COLUMN_UNIQUE/%d",
@@ -541,7 +442,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"FALSE",
NULL,
"/FIELDS_A/@COLUMN_PKEY/%d",
@@ -549,7 +450,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"Project",
NULL,
"/FKEY_S/%d/FKEY_REF_TABLE",
@@ -557,7 +458,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"RESTRICT",
NULL,
"/FKEY_S/%d/FKEY_ONDELETE",
@@ -565,7 +466,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"RESTRICT",
NULL,
"/FKEY_S/%d/FKEY_ONUPDATE",
@@ -573,7 +474,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"project_id",
NULL,
"/FKEY_S/%d/FKEY_FIELDS_A/@FK_FIELD/%d",
@@ -581,7 +482,7 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"id",
NULL,
"/FKEY_S/%d/FKEY_FIELDS_A/@FK_REF_PK_FIELD/%d",
@@ -591,59 +492,58 @@ test_server_operation_operations (TestObjectFixture *fixture,
res = gda_server_provider_perform_operation (fixture->provider,
fixture->cnc,
- fixture->op,
+ op,
NULL);
g_assert_true (res);
/* END of CREATE_TABLE operation */
- g_clear_object (&fixture->op);
+ g_clear_object (&op);
/* Start of ADD_COLUMN operation */
- fixture->op = gda_server_provider_create_operation (fixture->provider,
- fixture->cnc,
- GDA_SERVER_OPERATION_ADD_COLUMN,
- NULL,
- NULL);
+ op = gda_server_provider_create_operation (fixture->provider, fixture->cnc,
+ GDA_SERVER_OPERATION_ADD_COLUMN,
+ NULL,
+ NULL);
- g_assert_nonnull (fixture->op);
+ g_assert_nonnull (op);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"Project",
NULL,
"/COLUMN_DEF_P/TABLE_NAME");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"cost",
NULL,
"/COLUMN_DEF_P/COLUMN_NAME");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"gfloat",
NULL,
"/COLUMN_DEF_P/COLUMN_TYPE");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"5",
NULL,
"/COLUMN_DEF_P/COLUMN_SIZE");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"2",
NULL,
"/COLUMN_DEF_P/COLUMN_SCALE");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"FALSE",
NULL,
"/COLUMN_DEF_P/COLUMN_NNUL");
@@ -652,31 +552,29 @@ test_server_operation_operations (TestObjectFixture *fixture,
res = gda_server_provider_perform_operation (fixture->provider,
fixture->cnc,
- fixture->op,
+ op,
NULL);
g_assert_true (res);
- /* END OF ADD_COLUMN operation */
- g_clear_object (&fixture->op);
+ g_clear_object (&op);
/* START RENAME_TABLE OPERATION */
- fixture->op = gda_server_provider_create_operation (fixture->provider,
- fixture->cnc,
- GDA_SERVER_OPERATION_RENAME_TABLE,
- NULL,
- NULL);
+ op = gda_server_provider_create_operation (fixture->provider, fixture->cnc,
+ GDA_SERVER_OPERATION_RENAME_TABLE,
+ NULL,
+ NULL);
- g_assert_nonnull (fixture->op);
+ g_assert_true (op);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"Employee",
NULL,
"/TABLE_DESC_P/TABLE_NAME");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"NewEmployee",
NULL,
"/TABLE_DESC_P/TABLE_NEW_NAME");
@@ -685,46 +583,46 @@ test_server_operation_operations (TestObjectFixture *fixture,
res = gda_server_provider_perform_operation (fixture->provider,
fixture->cnc,
- fixture->op,
+ op,
NULL);
g_assert_true (res);
/* END RENAME_TABLE OPERATION */
- g_clear_object (&fixture->op);
+ g_clear_object (&op);
/* START CREATE_VIEW OPERATION */
- fixture->op = gda_server_provider_create_operation (fixture->provider,
- fixture->cnc,
- GDA_SERVER_OPERATION_CREATE_VIEW,
- NULL,
- NULL);
+ op = gda_server_provider_create_operation (fixture->provider,
+ fixture->cnc,
+ GDA_SERVER_OPERATION_CREATE_VIEW,
+ NULL,
+ NULL);
- g_assert_nonnull (fixture->op);
+ g_assert_nonnull (op);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"MyView",
NULL,
"/VIEW_DEF_P/VIEW_NAME");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"FALSE",
NULL,
"/VIEW_DEF_P/VIEW_TEMP");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/VIEW_DEF_P/VIEW_IFNOTEXISTS");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
- "SELECT name, project_id FROM Employee",
+ res = gda_server_operation_set_value_at (op,
+ "SELECT name, project_id FROM NewEmployee",
NULL,
"/VIEW_DEF_P/VIEW_DEF");
@@ -732,85 +630,85 @@ test_server_operation_operations (TestObjectFixture *fixture,
res = gda_server_provider_perform_operation (fixture->provider,
fixture->cnc,
- fixture->op,
+ op,
NULL);
g_assert_true (res);
/* END CREATE_VIEEW OPERATION */
- g_clear_object (&fixture->op);
+ g_clear_object (&op);
- /* START DROP_VIEEW OPERATION */
- fixture->op = gda_server_provider_create_operation (fixture->provider,
- fixture->cnc,
- GDA_SERVER_OPERATION_DROP_VIEW,
- NULL,
- NULL);
+ /* START DROP_VIEW OPERATION */
+ op = gda_server_provider_create_operation (fixture->provider,
+ fixture->cnc,
+ GDA_SERVER_OPERATION_DROP_VIEW,
+ NULL,
+ NULL);
- g_assert_nonnull (fixture->op);
+ g_assert_nonnull (op);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"MyView",
NULL,
"/VIEW_DESC_P/VIEW_NAME");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
- "/VIEW_DEF_P/VIEW_IFNOTEXISTS");
+ "/VIEW_DESC_P/VIEW_IFNOTEXISTS");
g_assert_true (res);
res = gda_server_provider_perform_operation (fixture->provider,
fixture->cnc,
- fixture->op,
+ op,
NULL);
g_assert_true (res);
- /* END CREATE_VIEEW OPERATION */
+ /* END DROP VIEW OPERATION */
- g_clear_object (&fixture->op);
+ g_clear_object (&op);
/* START CREATE_INDEX OPERATION */
- fixture->op = gda_server_provider_create_operation (fixture->provider,
- fixture->cnc,
- GDA_SERVER_OPERATION_CREATE_INDEX,
- NULL,
- NULL);
+ op = gda_server_provider_create_operation (fixture->provider,
+ fixture->cnc,
+ GDA_SERVER_OPERATION_CREATE_INDEX,
+ NULL,
+ NULL);
- g_assert_nonnull (fixture->op);
+ g_assert_nonnull (op);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"UNIQUE",
NULL,
"/INDEX_DEF_P/INDEX_TYPE");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"MyIndex",
NULL,
"/INDEX_DEF_P/INDEX_NAME");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"NewEmployee",
NULL,
"/INDEX_DEF_P/INDEX_ON_TABLE");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/INDEX_DEF_P/INDEX_IFNOTEXISTS");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"name",
NULL,
"/INDEX_FIELDS_S/%d/INDEX_FIELD",
@@ -818,15 +716,15 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
- "NOCASE",
+ res = gda_server_operation_set_value_at (op,
+ "BINARY",
NULL,
"/INDEX_FIELD_S/%d/INDEX_COLLATE",
0);
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"ASC",
NULL,
"/INDEX_FIELD_S/%d/INDEX_SORT_ORDER",
@@ -834,32 +732,29 @@ test_server_operation_operations (TestObjectFixture *fixture,
g_assert_true (res);
- res = gda_server_provider_perform_operation (fixture->provider,
- fixture->cnc,
- fixture->op,
- NULL);
+ res = gda_server_provider_perform_operation (fixture->provider, fixture->cnc, op, NULL);
g_assert_true (res);
/* END CREATE_INDEX OPERATION */
- g_clear_object (&fixture->op);
+ g_clear_object (&op);
/* START DROP_INDEX OPERATION */
- fixture->op = gda_server_provider_create_operation (fixture->provider,
- fixture->cnc,
- GDA_SERVER_OPERATION_DROP_INDEX,
- NULL,
- NULL);
+ op = gda_server_provider_create_operation (fixture->provider,
+ fixture->cnc,
+ GDA_SERVER_OPERATION_DROP_INDEX,
+ NULL,
+ NULL);
- g_assert_nonnull (fixture->op);
+ g_assert_nonnull (op);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"MyIndex",
NULL,
"/INDEX_DESC_P/INDEX_NAME");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/INDEX_DESC_P/INDEX_IFEXISTS");
@@ -868,31 +763,31 @@ test_server_operation_operations (TestObjectFixture *fixture,
res = gda_server_provider_perform_operation (fixture->provider,
fixture->cnc,
- fixture->op,
+ op,
NULL);
g_assert_true (res);
/* END DROP_INDEX OPERATION */
- g_clear_object(&fixture->op);
+ g_clear_object (&op);
/* START DROP_TABLE OPERATION */
- fixture->op = gda_server_provider_create_operation (fixture->provider,
- fixture->cnc,
- GDA_SERVER_OPERATION_DROP_TABLE,
- NULL,
- NULL);
+ op = gda_server_provider_create_operation (fixture->provider,
+ fixture->cnc,
+ GDA_SERVER_OPERATION_DROP_TABLE,
+ NULL,
+ NULL);
- g_assert_nonnull (fixture->op);
+ g_assert_nonnull (op);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"NewEmployee",
NULL,
"/TABLE_DESC_P/TABLE_NAME");
g_assert_true (res);
- res = gda_server_operation_set_value_at (fixture->op,
+ res = gda_server_operation_set_value_at (op,
"TRUE",
NULL,
"/TABLE_DESC_P/TABLE_IFEXISTS");
@@ -901,84 +796,180 @@ test_server_operation_operations (TestObjectFixture *fixture,
res = gda_server_provider_perform_operation (fixture->provider,
fixture->cnc,
- fixture->op,
+ op,
NULL);
g_assert_true (res);
/* END DROP_TABLE OPERATION */
+
+ g_object_unref (op);
}
-void
-test_server_operation_drop_db (TestObjectFixture *fixture,
- gconstpointer user_data)
+static void
+test_server_operation_operations_db (TestObjectFixture *fixture,
+ gconstpointer user_data)
{
- fixture->cnc = gda_connection_open_from_string (PROVIDER_NAME, fixture->cnc_string, NULL,
- GDA_CONNECTION_OPTIONS_NONE, NULL);
- g_assert_nonnull (fixture->cnc);
- fixture->provider = gda_connection_get_provider (fixture->cnc);
+/* Define table Project */
+ GdaDbTable *tproject = gda_db_table_new ();
+ gda_db_base_set_name (GDA_DB_BASE (tproject), "Project");
+ gda_db_table_set_is_temp (tproject, FALSE);
- g_assert_nonnull (fixture->provider);
+ /* Defining column id */
+ GdaDbColumn *pid = gda_db_column_new ();
+ gda_db_column_set_name (pid, "id");
+ gda_db_column_set_type (pid, G_TYPE_INT);
+ gda_db_column_set_nnul (pid, TRUE);
+ gda_db_column_set_autoinc (pid, TRUE);
+ gda_db_column_set_unique (pid, TRUE);
+ gda_db_column_set_pkey (pid, TRUE);
+
+ gda_db_table_append_column (tproject, pid);
- fixture->op = gda_server_provider_create_operation (fixture->provider,
- fixture->cnc,
- GDA_SERVER_OPERATION_CREATE_DB,
- NULL,
- NULL);
+ g_object_unref (pid);
+
+ /* Defining column name */
+ GdaDbColumn *pname = gda_db_column_new ();
+ gda_db_column_set_name (pname, "name");
+ gda_db_column_set_type (pname, G_TYPE_STRING);
+ gda_db_column_set_size (pname, 50);
+ gda_db_column_set_nnul (pname, TRUE);
+ gda_db_column_set_autoinc (pname, FALSE);
+ gda_db_column_set_unique (pname, TRUE);
+ gda_db_column_set_pkey (pname, FALSE);
+ gda_db_column_set_default (pname, "Default_name");
+
+ gda_db_table_append_column (tproject, pname);
+
+ g_object_unref (pname);
+
+/* Create table */
+ gboolean res = gda_db_table_create (tproject, fixture->cnc, TRUE, NULL);
+
+ g_assert_true (res);
- g_assert_nonnull (fixture->op);
+/* Define table Employee */
+ GdaDbTable *temployee = gda_db_table_new ();
+ gda_db_base_set_name (GDA_DB_BASE (temployee), "Employee");
+ gda_db_table_set_is_temp (temployee, FALSE);
- GdaQuarkList *db_quark_list = NULL;
- db_quark_list = gda_quark_list_new_from_string (fixture->cnc_string);
+ /* Defining column id */
+ GdaDbColumn *eid = gda_db_column_new ();
+ gda_db_column_set_name (eid, "id");
+ gda_db_column_set_type (eid, G_TYPE_INT);
+ gda_db_column_set_nnul (eid, TRUE);
+ gda_db_column_set_autoinc (eid, TRUE);
+ gda_db_column_set_unique (eid, TRUE);
+ gda_db_column_set_pkey (eid, TRUE);
- QuarkSet setval;
+ gda_db_table_append_column (temployee, eid);
- setval.prefix = g_strdup ("DB_DEF_P");
- setval.op = fixture->op;
+ g_object_unref (eid); /* We will reuse this object */
- gda_quark_list_foreach (db_quark_list, (GHFunc) set_val_quark_foreach_func, &setval);
+ GdaDbColumn *ename = gda_db_column_new ();
+ gda_db_column_set_name (ename, "name");
+ gda_db_column_set_type (ename, G_TYPE_STRING);
+ gda_db_column_set_size (ename, 50);
+ gda_db_column_set_nnul (ename, TRUE);
+ gda_db_column_set_autoinc (ename, FALSE);
+ gda_db_column_set_unique (ename, TRUE);
+ gda_db_column_set_pkey (ename, FALSE);
+ gda_db_column_set_default (ename, "Default_name");
- g_free (setval.prefix);
+ gda_db_table_append_column (temployee, ename);
- gboolean res = gda_server_provider_perform_operation (fixture->provider,
- fixture->cnc,
- fixture->op,
- NULL);
+ g_object_unref (ename); /* We will reuse this object */
+
+ GdaDbColumn *project_id = gda_db_column_new();
+ gda_db_column_set_name (project_id, "project_id");
+ gda_db_column_set_type (project_id, G_TYPE_INT);
+ gda_db_column_set_nnul (project_id, TRUE);
+ gda_db_column_set_autoinc (project_id, FALSE);
+ gda_db_column_set_unique (project_id, FALSE);
+ gda_db_column_set_pkey (project_id, FALSE);
+
+ gda_db_table_append_column (temployee, project_id);
+
+ g_object_unref (project_id);
+
+/* Creating Foreign key */
+ GdaDbFkey *fkey = gda_db_fkey_new ();
+ gda_db_fkey_set_ref_table (fkey, "Project");
+ gda_db_fkey_set_ondelete (fkey, GDA_DB_FKEY_RESTRICT);
+ gda_db_fkey_set_onupdate (fkey, GDA_DB_FKEY_RESTRICT);
+ gda_db_fkey_set_field (fkey, "project_id", "id");
+
+ gda_db_table_append_fkey (temployee, fkey);
+
+ g_object_unref (fkey);
+
+ res = gda_db_table_create (temployee, fixture->cnc, TRUE, NULL);
g_assert_true (res);
- /* We need to clean everything after CREATE_DB operation above */
- gda_connection_close (fixture->cnc, NULL);
- g_clear_object (&fixture->cnc);
- g_clear_object (&fixture->op);
- /* End of clean up block */
+ /* Start of ADD_COLUMN operation */
+ GdaDbColumn *cost = gda_db_column_new ();
+ gda_db_column_set_name (cost, "cost");
+ gda_db_column_set_type (cost, G_TYPE_FLOAT);
+ gda_db_column_set_size (cost, 5);
+ gda_db_column_set_scale (cost, 2);
+ gda_db_column_set_nnul (cost, FALSE);
- fixture->cnc = gda_connection_open_from_string (PROVIDER_NAME, fixture->cnc_string, NULL,
- GDA_CONNECTION_OPTIONS_NONE, NULL);
- g_assert_nonnull (fixture->cnc);
+ res = gda_db_table_add_column (tproject, cost, fixture->cnc, NULL);
- fixture->op = gda_server_provider_create_operation (fixture->provider,
- fixture->cnc,
- GDA_SERVER_OPERATION_DROP_DB,
- NULL,
- NULL);
+ g_assert_true (res);
- g_assert_nonnull (fixture->op);
+ g_object_unref (cost);
+ g_object_unref (tproject);
- db_quark_list = NULL;
- db_quark_list = gda_quark_list_new_from_string (fixture->cnc_string);
+/* RENAME_TABLE operation */
+ GdaDbTable *new_table = gda_db_table_new ();
+ gda_db_base_set_name (GDA_DB_BASE (new_table), "NewEmployee");
- setval.prefix = g_strdup ("DB_DESC_P"); // Prefix for op object
- setval.op = fixture->op;
+ res = gda_db_table_rename (temployee, new_table, fixture->cnc, NULL);
- gda_quark_list_foreach (db_quark_list, (GHFunc) set_val_quark_foreach_func, &setval);
+ g_assert_true (res);
- g_free (setval.prefix);
+ GdaDbView *myview = gda_db_view_new ();
+ gda_db_base_set_name (GDA_DB_BASE (myview), "MyView");
+ gda_db_view_set_istemp (myview, FALSE);
+ gda_db_view_set_defstring (myview, "SELECT name, project_id FROM NewEmployee");
- res = gda_server_provider_perform_operation (fixture->provider,
- fixture->cnc,
- fixture->op,
- NULL);
+ res = gda_db_view_create (myview, fixture->cnc, TRUE, NULL);
+
+ /* DROP_VIEW operation. We will reuse the view */
+ res = gda_db_view_drop (myview, fixture->cnc, TRUE, GDA_DB_VIEW_RESTRICT, NULL);
+
+ g_assert_true (res);
+
+ GdaDbIndex *index = gda_db_index_new ();
+
+ gda_db_index_set_unique (index, TRUE);
+ gda_db_base_set_name (GDA_DB_BASE (index), "MyIndex"); // GdaDBIndex is derived from GdaDbBase
+
+ GdaDbIndexField *field = gda_db_index_field_new ();
+
+ GdaDbColumn *fcol = gda_db_column_new ();
+
+ gda_db_column_set_name (fcol, "name");
+
+ gda_db_index_field_set_column (field, fcol);
+ gda_db_index_field_set_collate (field, GDA_DB_INDEX_COLLATE_BINARY);
+ gda_db_index_field_set_sort_order (field, GDA_DB_INDEX_SORT_ORDER_ASC);
+
+ gda_db_index_append_field (index, field);
+ g_object_unref (fcol);
+ g_object_unref (field);
+
+ res = gda_db_table_add_index (new_table, index, fixture->cnc, TRUE, NULL);
+
+ g_assert_true (res);
+
+ res = gda_db_index_drop (index, fixture->cnc, TRUE, NULL);
+
+ g_assert_true (res);
+
+ res = gda_db_table_drop (new_table, fixture->cnc, TRUE, NULL);
g_assert_true (res);
}
@@ -990,27 +981,20 @@ main(gint argc, gchar *argv[])
g_test_init (&argc,&argv,NULL);
- g_test_add ("/test-server-operation-sqlite/create-db",
+ g_test_add ("/test-server-operation-sqlite/old-so-module",
TestObjectFixture,
NULL,
test_server_operation_start,
- test_server_operation_create_db,
+ test_server_operation_operations,
test_server_operation_finish);
- g_test_add ("/test-server-operation-sqlite/drop-db",
+ g_test_add ("/test-server-operation-sqlite/gda-db-module",
TestObjectFixture,
NULL,
test_server_operation_start,
- test_server_operation_drop_db,
+ test_server_operation_operations_db,
test_server_operation_finish);
- g_test_add ("/test-server-operation-sqlite/create-table",
- TestObjectFixture,
- NULL,
- test_server_operation_operations_start,
- test_server_operation_operations,
- test_server_operation_operations_finish);
-
return g_test_run();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]