[gnome-db] Sybase patch



Hello all!

I've finally been able to do some hacking on the Sybase provider.

this patch does the following:
- adds support for index schema
- adds support for triggers schema
- adds support for begin/commit/rollback of transactions
- adds support for getting the current database

I've done all my testing against Sybase ASE 12.5 ( I can't get 
11.9.2 to install on Redhat 8.0 ) 

Mike







Index: providers/sybase/gda-sybase-provider.c
===================================================================
RCS file: /cvs/gnome/libgda/providers/sybase/gda-sybase-provider.c,v
retrieving revision 1.13
diff -u -u -r1.13 gda-sybase-provider.c
--- providers/sybase/gda-sybase-provider.c	16 Dec 2002 22:29:41 -0000	1.13
+++ providers/sybase/gda-sybase-provider.c	20 Dec 2002 17:15:27 -0000
@@ -41,12 +41,12 @@
 static void gda_sybase_provider_finalize (GObject *object);
 
 static gboolean gda_sybase_provider_open_connection (GdaServerProvider *provider,
-						     GdaConnection *cnc,
-						     GdaQuarkList *params,
-						     const gchar *username,
-						     const gchar *password);
+																																																					GdaConnection *cnc,
+																																																					GdaQuarkList *params,
+																																																					const gchar *username,
+																																																					const gchar *password);
 static gboolean gda_sybase_provider_close_connection (GdaServerProvider *provider,
-						      GdaConnection *cnc);
+																																																						GdaConnection *cnc);
 
 
 static gboolean gda_sybase_provider_begin_transaction (GdaServerProvider *provider,
@@ -75,7 +75,7 @@
                                                      GdaConnectionSchema schema,
                                                      GdaParameterList *params);
 static const gchar *gda_sybase_provider_get_server_version (GdaServerProvider *provider,
-                                        GdaConnection *cnc);
+																																																												GdaConnection *cnc);
 static const gchar *gda_sybase_provider_get_version (GdaServerProvider *provider);
 static gboolean gda_sybase_provider_rollback_transaction (GdaServerProvider *provider,
                                                           GdaConnection *cnc,
@@ -127,7 +127,7 @@
 
 static void
 gda_sybase_provider_init (GdaSybaseProvider *myprv, 
-			  GdaSybaseProviderClass *klass)
+																										GdaSybaseProviderClass *klass)
 {
 }
 
@@ -159,8 +159,8 @@
 			(GInstanceInitFunc) gda_sybase_provider_init
 		};
 		type = g_type_register_static (PARENT_TYPE,
-					       "GdaSybaseProvider",
-					       &info, 0);
+																																	"GdaSybaseProvider",
+																																	&info, 0);
 	}
 
 	return type;
@@ -173,14 +173,30 @@
 
 	provider = g_object_new (gda_sybase_provider_get_type (), NULL);
 
+
+	g_print("loading sybase provider!\n");
+
 	return GDA_SERVER_PROVIDER (provider);
 }
 
 GdaSybaseConnectionData *
 gda_sybase_connection_data_new(void)
 {
+
+	// here!
+
 	GdaSybaseConnectionData *sconn = g_new0 (GdaSybaseConnectionData, 1);
 
+	if ( !sconn) 
+		return NULL;
+
+	sconn->server_version = NULL;
+	sconn->gda_cnc = NULL;
+	sconn->context = NULL;
+	sconn->cmd = NULL;
+	sconn->connection = NULL;
+	sconn->mempool = NULL;
+
 	return sconn;
 }
 
@@ -196,7 +212,7 @@
 			// we do not check if the handle is the same,
 			// because it must be identical (connection_open)
 			g_object_set_data (G_OBJECT (sconn->gda_cnc), 
-			                   OBJECT_DATA_SYBASE_HANDLE, NULL);
+																						OBJECT_DATA_SYBASE_HANDLE, NULL);
 			// is just a reference copy
 			sconn->gda_cnc = NULL;
 		}
@@ -229,10 +245,10 @@
 /* open_connection handler for the GdaSybaseProvider class */
 static gboolean
 gda_sybase_provider_open_connection (GdaServerProvider *provider,
-				     GdaConnection *cnc,
-				     GdaQuarkList *params,
-				     const gchar *username,
-				     const gchar *password)
+																																					GdaConnection *cnc,
+																																					GdaQuarkList *params,
+																																					const gchar *username,
+																																					const gchar *password)
 {
 		
 	GdaSybaseConnectionData *sconn = NULL;
@@ -269,17 +285,19 @@
 	t_locale = gda_quark_list_find (params, "LOCALE");
 
 	sybase_debug_msg ("username: '%s', password '%s'",
-	                  (t_user != NULL) ? t_user : "(NULL)",
-	                  (t_password != NULL) ? "XXXXXXXX" : "(NULL)");
+																			(t_user != NULL) ? t_user : "(NULL)",
+																			(t_password != NULL) ? "XXXXXXXX" : "(NULL)");
 	
-	sconn = g_new0 (GdaSybaseConnectionData, 1);
+	//		sconn = g_new0 (GdaSybaseConnectionData, 1);
+	sconn = gda_sybase_connection_data_new();
+
 	if (!sconn) {
 		sybase_debug_msg (_("Out of memory. Allocating connection structure failed."));
 		return FALSE;
 	}
 
 	/* CS_GDA_VERSION is set to the latest CS_VERSION available
-	 * alloc context */
+		* alloc context */
 	sconn->ret = cs_ctx_alloc (CS_GDA_VERSION, &sconn->context);
 	if (sconn->ret != CS_SUCCEED) {
 		g_free (sconn);
@@ -299,31 +317,31 @@
 	if (t_locale) {
 		sconn->ret = cs_loc_alloc (sconn->context, &locale);
 		/* locale setting should not make connection fail
-		 * 
-		 * avoid nested if clauses because of same condition */
+			* 
+			* avoid nested if clauses because of same condition */
 		if (sconn->ret == CS_SUCCEED) {
 			sconn->ret = cs_locale (sconn->context,
-			                        CS_SET,
-			                        locale,
-			                        CS_LC_ALL,
-			                        (CS_CHAR *) t_locale,
-			                        CS_NULLTERM,
-			                        NULL);
+																											CS_SET,
+																											locale,
+																											CS_LC_ALL,
+																											(CS_CHAR *) t_locale,
+																											CS_NULLTERM,
+																											NULL);
 		}
 		if (sconn->ret == CS_SUCCEED) {
 			sconn->ret = cs_config (sconn->context,
-			                        CS_SET,
-			                        CS_LOC_PROP,
-			                        locale,
-			                        CS_UNUSED,
-			                        NULL);
+																											CS_SET,
+																											CS_LOC_PROP,
+																											locale,
+																											CS_UNUSED,
+																											NULL);
 		}
 		if (sconn->ret == CS_SUCCEED) {
 			sybase_debug_msg (_("Locale set to '%s'."), t_locale);
 		}
 		if (locale) {
 			sconn->ret = cs_loc_drop (sconn->context,
-			                          locale);
+																													locale);
 			locale = NULL;
 		}
 	}
@@ -331,8 +349,8 @@
 	/* Initialize callback handlers */
 	/*   cs */
 	sconn->ret = cs_config (sconn->context, CS_SET, CS_MESSAGE_CB,
-	                        (CS_VOID *) gda_sybase_csmsg_callback,
-	                         CS_UNUSED, NULL);
+																									(CS_VOID *) gda_sybase_csmsg_callback,
+																									CS_UNUSED, NULL);
 	if (sconn->ret != CS_SUCCEED) {
 		sybase_debug_msg(_("Could not initialize cslib callback"));
 		gda_sybase_connection_data_free (sconn);
@@ -341,8 +359,8 @@
 	sybase_debug_msg(_("CS-lib callback initialized."));
 	/*   ct-cli */
 	sconn->ret = ct_callback (sconn->context, NULL, CS_SET,
-	                          CS_CLIENTMSG_CB,
-	                          (CS_VOID *) gda_sybase_clientmsg_callback);
+																											CS_CLIENTMSG_CB,
+																											(CS_VOID *) gda_sybase_clientmsg_callback);
 	if (sconn->ret != CS_SUCCEED) {
 		sybase_debug_msg(_("Could not initialize ct-client callback"));
 		gda_sybase_connection_data_free (sconn);
@@ -352,8 +370,8 @@
 	
 	/*   ct-srv */
 	sconn->ret = ct_callback (sconn->context, NULL, CS_SET, 
-	                          CS_SERVERMSG_CB,
-	                          (CS_VOID *) gda_sybase_servermsg_callback);
+																											CS_SERVERMSG_CB,
+																											(CS_VOID *) gda_sybase_servermsg_callback);
 	if (sconn->ret != CS_SUCCEED) {
 		sybase_debug_msg(_("Could not initialize ct-server callback"));
 		gda_sybase_connection_data_free (sconn);
@@ -369,40 +387,42 @@
 	}
 	sybase_debug_msg(_("Connection allocated."));
 	/* init inline error handling for cs-lib */
-/*	sconn->ret = cs_diag (sconn->context, 
-	                      CS_INIT, 
-	                      CS_UNUSED, 
-	                      CS_UNUSED,
-	                      NULL);		
-	if (sconn->ret != CS_SUCCEED) {
-		gda_sybase_connection_data_free (sconn);
-		return FALSE;
-	}
-	sybase_debug_msg(_("Error handling for cs-lib initialized.")); */
+	/*	sconn->ret = cs_diag (sconn->context, 
+				CS_INIT, 
+				CS_UNUSED, 
+				CS_UNUSED,
+				NULL);		
+				if (sconn->ret != CS_SUCCEED) {
+				gda_sybase_connection_data_free (sconn);
+				return FALSE;
+				}
+				sybase_debug_msg(_("Error handling for cs-lib initialized.")); */
 	/* init inline error handling for ct-lib */
-/*	sconn->ret = ct_diag (sconn->connection, 
-	                      CS_INIT, 
-	                      CS_UNUSED, 
-	                      CS_UNUSED,
-	                      NULL);
-	if (sconn->ret != CS_SUCCEED) {
-		gda_sybase_connection_data_free (sconn);
-		return FALSE;
-	}
-	sybase_debug_msg(_("Error handling for ct-lib initialized.")); */
+	/*	sconn->ret = ct_diag (sconn->connection, 
+				CS_INIT, 
+				CS_UNUSED, 
+				CS_UNUSED,
+				NULL);
+				if (sconn->ret != CS_SUCCEED) {
+				gda_sybase_connection_data_free (sconn);
+				return FALSE;
+				}
+				sybase_debug_msg(_("Error handling for ct-lib initialized.")); */
 
 	/* set object data for error handling routines */
 	sconn->gda_cnc = cnc; /* circular reference for freeing */
+
 	g_object_set_data (G_OBJECT (cnc), OBJECT_DATA_SYBASE_HANDLE, sconn);
+
 	/* now first check possible, do so */
 	
 	/* set appname */
 	sconn->ret = ct_con_props (sconn->connection, 
-	                           CS_SET, 
-	                           CS_APPNAME, 
-	                           (CS_CHAR *) "gda-sybase provider", 
-	                           CS_NULLTERM, 
-	                           NULL);
+																												CS_SET, 
+																												CS_APPNAME, 
+																												(CS_CHAR *) "gda-sybase provider", 
+																												CS_NULLTERM, 
+																												NULL);
 	if (sconn->ret != CS_SUCCEED) {
 		gda_sybase_connection_data_free (sconn);
 		return FALSE;
@@ -411,11 +431,11 @@
 
 	/* set username */
 	sconn->ret = ct_con_props (sconn->connection, 
-	                           CS_SET, 
-	                           CS_USERNAME, 
-	                           (CS_CHAR *) t_user,
-	                           CS_NULLTERM, 
-	                           NULL);
+																												CS_SET, 
+																												CS_USERNAME, 
+																												(CS_CHAR *) t_user,
+																												CS_NULLTERM, 
+																												NULL);
 	if (sconn->ret != CS_SUCCEED) {
 		gda_sybase_connection_data_free (sconn);
 		return FALSE;
@@ -425,11 +445,11 @@
 	/* assume null-length passwords as passwordless logins */
 	if ((t_password != NULL) && (strlen(t_password) > 0)) {
 		sconn->ret = ct_con_props (sconn->connection, 
-		                           CS_SET, 
-		                           CS_PASSWORD, 
-		                           (CS_CHAR *) t_password,
-		                           CS_NULLTERM, 
-		                           NULL);
+																													CS_SET, 
+																													CS_PASSWORD, 
+																													(CS_CHAR *) t_password,
+																													CS_NULLTERM, 
+																													NULL);
 		if (sconn->ret != CS_SUCCEED) {
 			gda_sybase_connection_data_free (sconn);
 			return FALSE;
@@ -437,11 +457,11 @@
 		sybase_debug_msg(_("Password set."));
 	} else {
 		sconn->ret = ct_con_props (sconn->connection, 
-		                           CS_SET, 
-		                           CS_PASSWORD, 
-		                           (CS_CHAR *) "",
-		                           CS_NULLTERM, 
-		                           NULL);
+																													CS_SET, 
+																													CS_PASSWORD, 
+																													(CS_CHAR *) "",
+																													CS_NULLTERM, 
+																													NULL);
 		if (sconn->ret != CS_SUCCEED) {
 			gda_sybase_connection_data_free (sconn);
 			return FALSE;
@@ -449,9 +469,9 @@
 		sybase_debug_msg(_("Empty password set."));
 	}
 	sconn->ret = ct_connect (sconn->connection, 
-	                         (t_host) ? ((CS_CHAR *) t_host)
-	                                  : ((CS_CHAR *) NULL), 
-	                         (t_host) ? strlen(t_host) : 0);
+																										(t_host) ? ((CS_CHAR *) t_host)
+																										: ((CS_CHAR *) NULL), 
+																										(t_host) ? strlen(t_host) : 0);
 	if (sconn->ret != CS_SUCCEED) {
 		gda_sybase_connection_data_free (sconn);
 		return FALSE;
@@ -463,11 +483,11 @@
 	
 	/* get the hostname from SQL server as a test */
 	sconn->ret = ct_con_props (sconn->connection, 
-	                           CS_GET, 
-	                           CS_SERVERNAME, 
-	                           &buf,
-	                           CS_MAX_CHAR, 
-	                           NULL);
+																												CS_GET, 
+																												CS_SERVERNAME, 
+																												&buf,
+																												CS_MAX_CHAR, 
+																												NULL);
 	if (sconn->ret != CS_SUCCEED) {
 		gda_sybase_connection_data_free (sconn);
 		
@@ -482,7 +502,7 @@
 /* close_connection handler for the GdaSybaseProvider class */
 static gboolean
 gda_sybase_provider_close_connection (GdaServerProvider *provider, 
-				      GdaConnection *cnc)
+																																						GdaConnection *cnc)
 {
 	GdaSybaseConnectionData *sconn;
 	g_return_val_if_fail (GDA_IS_SYBASE_PROVIDER (provider), FALSE);
@@ -505,7 +525,7 @@
                                       GdaConnection *cnc,
                                       GdaTransaction *xaction)
 {
-	return FALSE;
+	return ( gda_sybase_execute_cmd(cnc,"begin transaction") );
 }
 
 static gboolean
@@ -523,7 +543,7 @@
 	sql_cmd = g_strdup_printf("USE %s", name);
 	ret = gda_sybase_execute_cmd(cnc, sql_cmd);
 	g_free(sql_cmd);
-	
+
 	return ret;
 }
 
@@ -532,7 +552,7 @@
                                         GdaConnection *cnc,
                                         GdaTransaction *xaction)
 {
-	return FALSE;
+	return ( gda_sybase_execute_cmd(cnc,"commit transaction") );		
 }
 
 static gboolean 
@@ -567,27 +587,27 @@
 	g_return_val_if_fail (cmd != NULL, NULL);
 
 	switch (gda_command_get_command_type (cmd)) {
-		case GDA_COMMAND_TYPE_SQL:
-			reclist = gda_sybase_provider_process_sql_commands (reclist, cnc, gda_command_get_text (cmd));
-			break;
-		case GDA_COMMAND_TYPE_TABLE:
-			query = g_strdup_printf ("SELECT * FROM %s", gda_command_get_text (cmd));
-			reclist = gda_sybase_provider_process_sql_commands (reclist, cnc, query);
-			if (reclist && GDA_IS_DATA_MODEL (reclist->data)) {
-				gda_data_model_set_command_text (GDA_DATA_MODEL (reclist->data),
-				                                 gda_command_get_text (cmd));
-				gda_data_model_set_command_type (GDA_DATA_MODEL (reclist->data),
-				                                 GDA_COMMAND_TYPE_TABLE);
-			}
-			g_free(query);
-			query = NULL;
-			break;
-		case GDA_COMMAND_TYPE_XML:
-		case GDA_COMMAND_TYPE_PROCEDURE:
-		case GDA_COMMAND_TYPE_SCHEMA:
-		case GDA_COMMAND_TYPE_INVALID:
-			return reclist;
-			break;
+	case GDA_COMMAND_TYPE_SQL:
+		reclist = gda_sybase_provider_process_sql_commands (reclist, cnc, gda_command_get_text (cmd));
+		break;
+	case GDA_COMMAND_TYPE_TABLE:
+		query = g_strdup_printf ("SELECT * FROM %s", gda_command_get_text (cmd));
+		reclist = gda_sybase_provider_process_sql_commands (reclist, cnc, query);
+		if (reclist && GDA_IS_DATA_MODEL (reclist->data)) {
+			gda_data_model_set_command_text (GDA_DATA_MODEL (reclist->data),
+																																				gda_command_get_text (cmd));
+			gda_data_model_set_command_type (GDA_DATA_MODEL (reclist->data),
+																																				GDA_COMMAND_TYPE_TABLE);
+		}
+		g_free(query);
+		query = NULL;
+		break;
+	case GDA_COMMAND_TYPE_XML:
+	case GDA_COMMAND_TYPE_PROCEDURE:
+	case GDA_COMMAND_TYPE_SCHEMA:
+	case GDA_COMMAND_TYPE_INVALID:
+		return reclist;
+		break;
 	}
 
 	return reclist;
@@ -623,17 +643,17 @@
 			scnc->ret = ct_cmd_alloc (scnc->connection, &scnc->cmd);
 			if (scnc->ret != CS_SUCCEED) {
 				sybase_debug_msg(_("Failed allocating a command structure in %s()"),
-				                 __FUNCTION__);
+																					__FUNCTION__);
 				return NULL;
 			}
 
 
 			// execute _single_ sql query (one stmt)
 			scnc->ret = ct_command (scnc->cmd, CS_LANG_CMD,
-			                        arr[n], CS_NULLTERM, CS_UNUSED);
+																											arr[n], CS_NULLTERM, CS_UNUSED);
 			if (scnc->ret != CS_SUCCEED) {
 				error = gda_sybase_make_error (scnc,
-					_("Could not prepare command structure."));
+																																			_("Could not prepare command structure."));
 				gda_connection_add_error (cnc, error);
 				ct_cmd_drop (scnc->cmd);
 				scnc->cmd = NULL;
@@ -642,7 +662,7 @@
 			scnc->ret = ct_send(scnc->cmd);
 			if (scnc->ret != CS_SUCCEED) {
 				error = gda_sybase_make_error (scnc,
-					_("Sending sql-command failed."));
+																																			_("Sending sql-command failed."));
 				gda_connection_add_error (cnc, error);
 				ct_cmd_drop (scnc->cmd);
 				scnc->cmd = NULL;
@@ -654,9 +674,8 @@
 			
 			// part 1: process results in while-loop
 			while ((scnc->rret = ct_results (scnc->cmd,
-			                                 &scnc->res_type
-                                                        )
-			       ) == CS_SUCCEED) {
+																																				&scnc->res_type)
+											) == CS_SUCCEED) {
 				// gda_sybase_recordset_new ()
 				// just returns a datamodel, 
 				// if we have a query with results...
@@ -666,47 +685,46 @@
 					gda_data_model_set_command_text (recset, arr[n]);
 					gda_data_model_set_command_type (recset, GDA_COMMAND_TYPE_SQL);
 					reclist = g_list_append (reclist, recset);
-	                        } else {
+				} 
+				else {
 				}
-
 				// this is done within gda_sybase_recordset_new()
-/*				switch (scnc->res_type) {
-					case CS_ROW_RESULT:
-						break;
-					case CS_CURSOR_RESULT:
-						break;
-					case CS_PARAM_RESULT:
-						break;
-					case CS_STATUS_RESULT:
-						break;
-					case CS_COMPUTE_RESULT:
-						break;
-					case CS_MSG_RESULT:
-						break;
-					case CS_DESCRIBE_RESULT:
-						break;
-					case CS_ROWFMT_RESULT:
-						break;
-					case CS_COMPUTEFMT_RESULT:
-						break;
-					case CS_CMD_DONE:
-						break;
-					case CS_CMD_SUCCEED:
-						break;
-					case CS_CMD_FAIL:
-						break;
-				}
-*/
+				/*				switch (scnc->res_type) {
+										case CS_ROW_RESULT:
+										break;
+										case CS_CURSOR_RESULT:
+										break;
+										case CS_PARAM_RESULT:
+										break;
+										case CS_STATUS_RESULT:
+										break;
+										case CS_COMPUTE_RESULT:
+										break;
+										case CS_MSG_RESULT:
+										break;
+										case CS_DESCRIBE_RESULT:
+										break;
+										case CS_ROWFMT_RESULT:
+										break;
+										case CS_COMPUTEFMT_RESULT:
+										break;
+										case CS_CMD_DONE:
+										break;
+										case CS_CMD_SUCCEED:
+										break;
+										case CS_CMD_FAIL:
+										break;
+										}*/
 			}
 
 			// part 2: have a look at the final returncode
 			switch (scnc->rret) {
-				case CS_END_RESULTS:
-					break;
-				case CS_CANCELED:
-					break;
-				case CS_FAIL:
-					break;
+			case CS_END_RESULTS:
+				break;
+			case CS_CANCELED:
+				break;
+			case CS_FAIL:
+				break;
 			}
 
 			scnc->ret = ct_cmd_drop (scnc->cmd);
@@ -716,7 +734,7 @@
 				scnc->cmd = NULL;
 			}
 			
-                        n++;
+			n++;
 		}
 		g_strfreev(arr);
 	}
@@ -742,7 +760,7 @@
 	
 	if (scnc->cmd != NULL) {
 		error = gda_sybase_make_error (scnc, _("Command structure already in use. %s failed."),
-		                               __FUNCTION__);
+																																	__FUNCTION__);
 		gda_connection_add_error (cnc, error);
 		return FALSE;
 	}
@@ -755,7 +773,7 @@
 	}
 
 	scnc->ret = ct_command (scnc->cmd, CS_LANG_CMD, (CS_CHAR *) sql, 
-	                        CS_NULLTERM, CS_UNUSED);
+																									CS_NULLTERM, CS_UNUSED);
 	if (scnc->ret != CS_SUCCEED) {
 		error = gda_sybase_make_error (scnc, _("Could not prepare command structure with %s."), "ct_command()");
 		gda_connection_add_error (cnc, error);
@@ -776,37 +794,37 @@
 	// proceed result codes, ct_cancel unexpected resultsets
 	while ((scnc->ret = ct_results (scnc->cmd, &res_type)) == CS_SUCCEED) {
 		switch (res_type) {
-			case CS_CMD_SUCCEED:
-			case CS_CMD_DONE:
-				break;
-
-			case CS_CMD_FAIL:
-				ret = FALSE;
-				break;
+		case CS_CMD_SUCCEED:
+		case CS_CMD_DONE:
+			break;
 
-			case CS_STATUS_RESULT:
-				scnc->ret = ct_cancel (NULL, scnc->cmd,
-				                       CS_CANCEL_CURRENT);
-				if (scnc->ret != CS_SUCCEED) {
-					error = gda_sybase_make_error (
-						scnc,
-						_("%s: %s failed"), __FUNCTION__, "ct_cancel");
-					gda_connection_add_error (cnc, error);
-					ret = FALSE;
-				}
-				break;
+		case CS_CMD_FAIL:
+			ret = FALSE;
+			break;
 
-			default:
+		case CS_STATUS_RESULT:
+			scnc->ret = ct_cancel (NULL, scnc->cmd,
+																										CS_CANCEL_CURRENT);
+			if (scnc->ret != CS_SUCCEED) {
+				error = gda_sybase_make_error (
+																																			scnc,
+																																			_("%s: %s failed"), __FUNCTION__, "ct_cancel");
+				gda_connection_add_error (cnc, error);
 				ret = FALSE;
+			}
+			break;
+
+		default:
+			ret = FALSE;
 		}
 		// cancel all result processing on failure
 		if (!ret) {
 			scnc->ret = ct_cancel (NULL, scnc->cmd,
-			                       CS_CANCEL_ALL);
+																										CS_CANCEL_ALL);
 			if (scnc->ret != CS_SUCCEED) {
 				error = gda_sybase_make_error (
-					scnc,
-					_("%s: %s failed"), __FUNCTION__, "ct_cancel");
+																																			scnc,
+																																			_("%s: %s failed"), __FUNCTION__, "ct_cancel");
 				gda_connection_add_error (cnc, error);
 			}
 		}
@@ -816,8 +834,8 @@
 		scnc->ret = ct_cmd_drop (scnc->cmd);
 		if (scnc->ret != CS_SUCCEED) {
 			error = gda_sybase_make_error (scnc,
-			            _("%s: %s failed"),
-			            __FUNCTION__, "ct_cmd_drop()");
+																																		_("%s: %s failed"),
+																																		__FUNCTION__, "ct_cmd_drop()");
 			gda_connection_add_error (cnc, error);
 			ret = FALSE;
 		} else {
@@ -837,40 +855,112 @@
                                   GdaConnection *cnc)
 {
 	GdaSybaseConnectionData *sconn = NULL;
-	CS_COMMAND *cmd = NULL;
+	CS_RETCODE ret,ret1,ret2,result_type;
+	CS_CHAR current_db[256];
+	CS_COMMAND     *cmd;
+	CS_DATAFMT column;
+	CS_INT datalen;
+	CS_SMALLINT indicator;
+	CS_INT count;
 
 	g_return_val_if_fail (provider != NULL, NULL);
 	g_return_val_if_fail (cnc != NULL, NULL);
 
-	sconn = (GdaSybaseConnectionData *) g_object_get_data (G_OBJECT (cnc),
-	                                                       OBJECT_DATA_SYBASE_HANDLE);
+	memset(current_db,'\0',256);
 
+	sconn = (GdaSybaseConnectionData *) g_object_get_data (G_OBJECT (cnc),
+																																																								OBJECT_DATA_SYBASE_HANDLE);
 	g_return_val_if_fail (sconn != NULL, NULL);
-	g_return_val_if_fail (sconn-> connection != NULL, NULL);
+	g_return_val_if_fail (sconn->connection != NULL, NULL);
+	g_return_val_if_fail (sconn->context != NULL, NULL);
+
+	ret = ct_cmd_alloc(sconn->connection, &cmd);
 	
-	sconn->ret = ct_cmd_alloc (sconn->connection, &cmd);
-	if (sconn->ret != CS_SUCCEED) {
-		if (sconn->ret == CS_BUSY) {
-			sybase_debug_msg (_("Connection already in use. Could not allocate command structure in %s()."), __FUNCTION__);
-		} else {
-			sybase_debug_msg (_("Could not allocate command structure."));
-		}
+	if ( ret != CS_SUCCEED ) {
+		sybase_debug_msg (_("could not allocate cmd structure to find current database."));
 		return NULL;
 	}
+	
+ ret = ct_command(cmd, 
+																		CS_LANG_CMD,
+																		TDS_QUERY_CURRENT_DATABASE,
+																		CS_NULLTERM, 
+																		CS_UNUSED); 	
 
+	if ( ret != CS_SUCCEED ) {
+		sybase_debug_msg (_("could not execute command to get current database."));
+		return NULL;
+	}
 
+	ret = ct_send(cmd);
 	
-//	ret = ct_send(sconn->connection, cmd);
-
-	sconn->ret = ct_cmd_drop (cmd);
-	if (sconn->ret != CS_SUCCEED) {
-		sybase_debug_msg (_("Failed dropping command structure in %s()."),
-		                  __FUNCTION__);
+	if ( ret != CS_SUCCEED ) {
+		sybase_debug_msg (_("could not send command to get current database."));
 		return NULL;
 	}
-	cmd = NULL;
+
+	while( (ret2 = ct_results(cmd, &result_type)) == CS_SUCCEED)
+		{
+			switch((int)result_type)
+				{
+				case CS_ROW_RESULT:
+					column.datatype = CS_CHAR_TYPE;
+					column.format = CS_FMT_NULLTERM;
+					column.maxlength = 255;
+					column.count = 1;
+					column.locale = NULL;
+					ret = ct_bind(cmd, 
+																			1, 
+																			&column,
+																			current_db, 
+																			&datalen,
+																			&indicator);
+
+					if ( ret != CS_SUCCEED ) {
+						sybase_debug_msg (_("could not bind variable to get current database."));
+						return NULL;
+					}
+
+					ret1 = ct_fetch(cmd, 
+																					CS_UNUSED, 
+																					CS_UNUSED,
+																					CS_UNUSED, 
+																					&count);
+
+
+					if ( ret != CS_SUCCEED ) {
+						sybase_debug_msg (_("could not fetch data to find current database."));
+						return NULL;
+					}
+
+					while(ret1 == CS_SUCCEED)
+						{
+							ret1 = ct_fetch(cmd, 
+																							CS_UNUSED, 
+																							CS_UNUSED,
+																							CS_UNUSED, 
+																							&count);							
+						}
+
+					if ( ret != CS_SUCCEED ) {
+						sybase_debug_msg (_("could not fetch data to find current database."));
+						return NULL;
+					}
+
+					break;
+				default:
+					break;
+				}
+		}
 	
-	return NULL;
+	ret = ct_cmd_drop(cmd);
+
+	if ( ret != CS_SUCCEED ) {
+		sybase_debug_msg (_("could not drop cmd structure to find current database."));
+		return NULL;
+	}
+
+	return ( g_strdup(current_db) );
 }
 
 static GdaDataModel *
@@ -880,7 +970,7 @@
 	GdaSybaseConnectionData *scnc = NULL;
 	g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
 	scnc = (GdaSybaseConnectionData *) g_object_get_data (G_OBJECT (cnc),
-	                                      OBJECT_DATA_SYBASE_HANDLE);
+																																																							OBJECT_DATA_SYBASE_HANDLE);
 	g_return_val_if_fail (scnc != NULL, NULL);
 
 	return NULL;
@@ -896,38 +986,38 @@
 	
 	g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
 	scnc = (GdaSybaseConnectionData *) g_object_get_data (G_OBJECT (cnc),
-	                                      OBJECT_DATA_SYBASE_HANDLE);
+																																																							OBJECT_DATA_SYBASE_HANDLE);
 	g_return_val_if_fail (scnc != NULL, NULL);
 
 	recset = (GdaDataModelArray *) gda_data_model_array_new (4);
 	gda_data_model_set_column_title (GDA_DATA_MODEL (recset),
-	                                 0, _("Type"));
+																																		0, _("Type"));
 	gda_data_model_set_column_title (GDA_DATA_MODEL (recset),
-	                                 1, _("Owner"));
+																																		1, _("Owner"));
 	gda_data_model_set_column_title (GDA_DATA_MODEL (recset),
-	                                 2, _("Comments"));
+																																		2, _("Comments"));
 	gda_data_model_set_column_title (GDA_DATA_MODEL (recset),
-	                                 3, _("GDA type"));
+																																		3, _("GDA type"));
 
 	for (i = 0; i < GDA_SYBASE_TYPE_CNT; i++) {
 		if (gda_sybase_type_list[i].name != NULL) {
 			GList *value_list = NULL;
 
 			value_list = g_list_append (value_list,
-			               gda_value_new_string (gda_sybase_type_list[i].name));
+																															gda_value_new_string (gda_sybase_type_list[i].name));
 			// FIXME: owner
-	                value_list = g_list_append (value_list,
-			               gda_value_new_string (""));
-	                value_list = g_list_append (value_list, 
-			               gda_value_new_string (""));
-	                value_list = g_list_append (value_list,
-			               gda_value_new_type (gda_sybase_type_list[i].gda_type));
-
-	                gda_data_model_append_row (GDA_DATA_MODEL (recset), value_list);
-	                g_list_foreach (value_list, (GFunc) gda_value_free, NULL);
-	                g_list_free (value_list);
+			value_list = g_list_append (value_list,
+																															gda_value_new_string (""));
+			value_list = g_list_append (value_list, 
+																															gda_value_new_string (""));
+			value_list = g_list_append (value_list,
+																															gda_value_new_type (gda_sybase_type_list[i].gda_type));
+
+			gda_data_model_append_row (GDA_DATA_MODEL (recset), value_list);
+			g_list_foreach (value_list, (GFunc) gda_value_free, NULL);
+			g_list_free (value_list);
 		}
-        }
+	}
 	
 	return GDA_DATA_MODEL (recset);
 }
@@ -939,62 +1029,72 @@
                                 GdaParameterList *params)
 {
 	GdaSybaseProvider *syb_prov = (GdaSybaseProvider *) provider;
-	gchar        *query = NULL;
 	GdaDataModel *recset = NULL;
 	
 	g_return_val_if_fail (GDA_IS_SYBASE_PROVIDER (syb_prov), NULL);
 	g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
 
 	switch (schema) {
-		case GDA_CONNECTION_SCHEMA_DATABASES:
-			recset = gda_sybase_execute_query (cnc, TDS_SCHEMA_DATABASES);
-			TDS_FIXMODEL_SCHEMA_DATABASES (recset);
-
-			return recset;
-			break;
-		case GDA_CONNECTION_SCHEMA_FIELDS:
-			return gda_sybase_get_fields (cnc, params);
-			break;
-		case GDA_CONNECTION_SCHEMA_PROCEDURES:
-			recset = gda_sybase_execute_query (cnc, TDS_SCHEMA_PROCEDURES);
-			TDS_FIXMODEL_SCHEMA_PROCEDURES (recset)
+	case GDA_CONNECTION_SCHEMA_DATABASES:
+		recset = gda_sybase_execute_query (cnc, TDS_SCHEMA_DATABASES);
+		TDS_FIXMODEL_SCHEMA_DATABASES (recset);
+
+		return recset;
+		break;
+	case GDA_CONNECTION_SCHEMA_FIELDS:
+		return gda_sybase_get_fields (cnc, params);
+		break;
+	case GDA_CONNECTION_SCHEMA_PROCEDURES:
+		recset = gda_sybase_execute_query (cnc, TDS_SCHEMA_PROCEDURES);
+		TDS_FIXMODEL_SCHEMA_PROCEDURES (recset)
 			
 			return recset;
-			break;
-		case GDA_CONNECTION_SCHEMA_TABLES:
-			recset = gda_sybase_execute_query (cnc, TDS_SCHEMA_TABLES);
-			TDS_FIXMODEL_SCHEMA_TABLES (recset)
+		break;
+	case GDA_CONNECTION_SCHEMA_TABLES:
+		recset = gda_sybase_execute_query (cnc, TDS_SCHEMA_TABLES);
+		TDS_FIXMODEL_SCHEMA_TABLES (recset)
 			
 			return recset;
-			break;
-		case GDA_CONNECTION_SCHEMA_TYPES:
-//			recset = gda_sybase_execute_query (cnc, TDS_SCHEMA_TYPES);
-//			TDS_FIXMODEL_SCHEMA_TYPES (recset)
-			recset = gda_sybase_provider_get_types (cnc, params);
-	
-			return recset;
-			break;
-		case GDA_CONNECTION_SCHEMA_USERS:
-			recset = gda_sybase_execute_query (cnc, TDS_SCHEMA_USERS);
-			TDS_FIXMODEL_SCHEMA_USERS (recset)
+		break;
+	case GDA_CONNECTION_SCHEMA_TYPES:
+		//			recset = gda_sybase_execute_query (cnc, TDS_SCHEMA_TYPES);
+		//			TDS_FIXMODEL_SCHEMA_TYPES (recset)
+		recset = gda_sybase_provider_get_types (cnc, params);
+		return recset;
+		break;
+	case GDA_CONNECTION_SCHEMA_USERS:
+		recset = gda_sybase_execute_query (cnc, TDS_SCHEMA_USERS);
+		TDS_FIXMODEL_SCHEMA_USERS (recset)
 				
 			return recset;
-			break;
-		case GDA_CONNECTION_SCHEMA_VIEWS:
-			recset = gda_sybase_execute_query (cnc, TDS_SCHEMA_VIEWS);
-			TDS_FIXMODEL_SCHEMA_VIEWS (recset)
+		break;
+	case GDA_CONNECTION_SCHEMA_VIEWS:
+		recset = gda_sybase_execute_query (cnc, TDS_SCHEMA_VIEWS);
+		TDS_FIXMODEL_SCHEMA_VIEWS (recset)
 
 			return recset;
-			break;
+		break;
+	case GDA_CONNECTION_SCHEMA_INDEXES:
+		recset = gda_sybase_execute_query (cnc, TDS_SCHEMA_INDEXES);
+		TDS_FIXMODEL_SCHEMA_INDEXES (recset);
+		
+		return recset;
+		break;				
+	case GDA_CONNECTION_SCHEMA_TRIGGERS:
+		recset = gda_sybase_execute_query (cnc, TDS_SCHEMA_TRIGGERS);
+		TDS_FIXMODEL_SCHEMA_TRIGGERS (recset);
+		
+		return recset;
+		break;				
 
-		// FIXME: Implement aggregates, indexes, sequences and triggers
-		case GDA_CONNECTION_SCHEMA_AGGREGATES:
-		case GDA_CONNECTION_SCHEMA_INDEXES:
-		case GDA_CONNECTION_SCHEMA_PARENT_TABLES:
-		case GDA_CONNECTION_SCHEMA_SEQUENCES:
-		case GDA_CONNECTION_SCHEMA_TRIGGERS:
-			return NULL;
-			break;
+		// FIXME: Implement aggregates, sequences 
+	case GDA_CONNECTION_SCHEMA_AGGREGATES:
+	case GDA_CONNECTION_SCHEMA_PARENT_TABLES:
+	case GDA_CONNECTION_SCHEMA_SEQUENCES:
+	case GDA_CONNECTION_SCHEMA_LANGUAGES:
+	case	GDA_CONNECTION_SCHEMA_NAMESPACES:
+		return NULL;
+		break;
 	}
 	
 	return NULL;
@@ -1012,7 +1112,7 @@
 	g_return_val_if_fail (sql != NULL, NULL);
 
 	scnc = (GdaSybaseConnectionData *) g_object_get_data (G_OBJECT (cnc),
-	                                       OBJECT_DATA_SYBASE_HANDLE);
+																																																							OBJECT_DATA_SYBASE_HANDLE);
 	g_return_val_if_fail (scnc != NULL, NULL);
 
 	model_list = gda_sybase_provider_process_sql_commands (NULL, cnc, sql);
@@ -1036,17 +1136,17 @@
 	g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
 	
 	scnc = (GdaSybaseConnectionData *) g_object_get_data (G_OBJECT (cnc),
-	                                       OBJECT_DATA_SYBASE_HANDLE);
+																																																							OBJECT_DATA_SYBASE_HANDLE);
 	g_return_val_if_fail (scnc != NULL, NULL);
 	if (!scnc->server_version) {
 		model = gda_sybase_execute_query (cnc, TDS_QUERY_SERVER_VERSION);
 		if (model) {
 			if ((gda_data_model_get_n_columns (model) == 1)
-			     && (gda_data_model_get_n_rows (model) == 1)) {
+							&& (gda_data_model_get_n_rows (model) == 1)) {
 				GdaValue *value;
 				
 				value = (GdaValue *) gda_data_model_get_value_at (model, 
-				                                                  0, 0);
+																																																						0, 0);
 				scnc->server_version = gda_value_stringify ((GdaValue *) value);
 			}
 			g_object_unref (model);
@@ -1072,7 +1172,7 @@
                                           GdaConnection *cnc,
                                           GdaTransaction *xaction)
 {
-	return FALSE;
+	return ( gda_sybase_execute_cmd(cnc,"rollback transaction") );		
 }
 
 static gboolean 
@@ -1085,23 +1185,23 @@
 	g_return_val_if_fail (GDA_IS_SYBASE_PROVIDER (syb_prov), FALSE);
 
 	switch (feature) {
-		case GDA_CONNECTION_FEATURE_PROCEDURES:
-		case GDA_CONNECTION_FEATURE_USERS:
-		case GDA_CONNECTION_FEATURE_VIEWS:
-		case GDA_CONNECTION_FEATURE_SQL:
-			return TRUE;
-
-	//FIXME: Implement missing 
-		case GDA_CONNECTION_FEATURE_AGGREGATES:
-		case GDA_CONNECTION_FEATURE_INDEXES:
-		case GDA_CONNECTION_FEATURE_INHERITANCE:
-		case GDA_CONNECTION_FEATURE_SEQUENCES:
-		case GDA_CONNECTION_FEATURE_TRANSACTIONS:
-		case GDA_CONNECTION_FEATURE_TRIGGERS:
-		case GDA_CONNECTION_FEATURE_XML_QUERIES:
-			return FALSE;
+	case GDA_CONNECTION_FEATURE_PROCEDURES:
+	case GDA_CONNECTION_FEATURE_USERS:
+	case GDA_CONNECTION_FEATURE_VIEWS:
+	case GDA_CONNECTION_FEATURE_SQL:
+	case GDA_CONNECTION_FEATURE_TRANSACTIONS:
+	case GDA_CONNECTION_FEATURE_INDEXES:
+	case GDA_CONNECTION_FEATURE_TRIGGERS:
+		return TRUE;
+
+		//FIXME: Implement missing 
+	case GDA_CONNECTION_FEATURE_AGGREGATES:
+	case GDA_CONNECTION_FEATURE_INHERITANCE:
+	case GDA_CONNECTION_FEATURE_SEQUENCES:
+	case GDA_CONNECTION_FEATURE_XML_QUERIES:
+	case GDA_CONNECTION_FEATURE_NAMESPACES:
+		return FALSE;
 	}
 	
 	return FALSE;
 }
-
Index: providers/sybase/gda-sybase-recordset.c
===================================================================
RCS file: /cvs/gnome/libgda/providers/sybase/gda-sybase-recordset.c,v
retrieving revision 1.3
diff -u -u -r1.3 gda-sybase-recordset.c
--- providers/sybase/gda-sybase-recordset.c	19 Dec 2002 12:30:02 -0000	1.3
+++ providers/sybase/gda-sybase-recordset.c	20 Dec 2002 17:15:29 -0000
@@ -476,7 +476,7 @@
 	GdaSybaseRecordset      *srecset = NULL;
 //	GdaSybaseField          *sfield = NULL;
 //	GdaRow                  *row = NULL;
-	GdaError                *error = NULL;
+//	GdaError                *error = NULL;
 //	gboolean                columns_set = FALSE;
 //	gint                    i = 0;
 
Index: providers/sybase/gda-sybase-schemas.h
===================================================================
RCS file: /cvs/gnome/libgda/providers/sybase/gda-sybase-schemas.h,v
retrieving revision 1.1
diff -u -u -r1.1 gda-sybase-schemas.h
--- providers/sybase/gda-sybase-schemas.h	19 Dec 2002 11:16:00 -0000	1.1
+++ providers/sybase/gda-sybase-schemas.h	20 Dec 2002 17:15:29 -0000
@@ -31,7 +31,7 @@
 G_BEGIN_DECLS
 
 #define TDS_QUERY_CURRENT_DATABASE \
-	"SELECT db_name() AS database"
+	"SELECT db_name()"
 #define TDS_QUERY_SERVER_VERSION \
 	"SELECT (@@version) AS version"
 
@@ -207,6 +207,32 @@
 	" ORDER BY name"
 
 G_END_DECLS
+
+
+#define TDS_SCHEMA_INDEXES \
+ "SELECT name from sysindexes " \
+ "order by name"
+
+
+#define TDS_FIXMODEL_SCHEMA_INDEXES(model) \
+	if (model) { \
+		gda_data_model_set_column_title (GDA_DATA_MODEL (model),  0, \
+		                                 _("Indexes")); \
+	}
+
+#define TDS_SCHEMA_TRIGGERS \
+ "SELECT name " \
+ "from sysobjects " \
+ "where type = 'TR' "\
+ "order by name"
+
+#define TDS_FIXMODEL_SCHEMA_TRIGGERS(model) \
+	if (model) { \
+		gda_data_model_set_column_title (GDA_DATA_MODEL (model),  0, \
+		                                 _("Triggers")); \
+	}
+
+
 
 #endif
 
Index: providers/sybase/gda-sybase-types.c
===================================================================
RCS file: /cvs/gnome/libgda/providers/sybase/gda-sybase-types.c,v
retrieving revision 1.1
diff -u -u -r1.1 gda-sybase-types.c
--- providers/sybase/gda-sybase-types.c	9 Dec 2002 05:45:01 -0000	1.1
+++ providers/sybase/gda-sybase-types.c	20 Dec 2002 17:15:30 -0000
@@ -81,7 +81,6 @@
                           GdaValue *value, GdaSybaseField *field)
 {
 	GdaError   *error = NULL;
-	GdaNumeric numeric;
 	gboolean   success = FALSE;
 	
 	g_return_val_if_fail (value != NULL, FALSE);
Index: providers/sybase/utils.c
===================================================================
RCS file: /cvs/gnome/libgda/providers/sybase/utils.c,v
retrieving revision 1.5
diff -u -u -r1.5 utils.c
--- providers/sybase/utils.c	16 Dec 2002 20:50:04 -0000	1.5
+++ providers/sybase/utils.c	20 Dec 2002 17:15:31 -0000
@@ -104,7 +104,7 @@
 {
 	GdaSybaseConnectionData *sconn;
 	
-	CS_CLIENTMSG msg;
+	//	CS_CLIENTMSG msg;
 	CS_INT       msgcnt = 0;
 	CS_INT       msgcur = 0;
Index: testing/sybase-test.c
===================================================================
RCS file: /cvs/gnome/libgda/testing/sybase-test.c,v
retrieving revision 1.1
diff -u -u -r1.1 sybase-test.c
--- testing/sybase-test.c	9 Dec 2002 05:44:59 -0000	1.1
+++ testing/sybase-test.c	20 Dec 2002 17:15:32 -0000
@@ -117,10 +117,18 @@
 do_sybase_test (GdaConnection *cnc)
 {
 	GList *list;
+	gchar *current_db;
+
 
 	g_return_if_fail (GDA_IS_CONNECTION (cnc));
 
 	g_print ("\tSybase provider specific tests...\n");
+
+	/* tests current get_database method */
+	current_db = gda_connection_get_database(cnc);
+	g_print("\t current database is.... %s\n",current_db);
+	g_free(current_db);
+
 
 	/* Drops the gda_sybase_test table. Fail if not exists. */
 	g_print ("\t\tDrop table: %s\n",


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