[gnome-db] sybase patch and a question
- From: Mike + Julie <wingert 3 postbox acs ohio-state edu>
- To: GDA <gnome-db-list gnome org>
- Subject: [gnome-db] sybase patch and a question
- Date: Wed, 21 Nov 2001 23:20:32 -0500
hello all,
here is another patch for the sybase provider, this makes error handling work
and fixes some problems when valid queries didn't return rows.
I look forward to hacking the new Sybase provider when I get some time to set
up a gnome 2 enviroment. How easy is it to set up the gnome-1.x and the
gnome2 enviroments side by side?
mike
? cvs.diff
Index: gda-sybase-command.c
===================================================================
RCS file: /cvs/gnome/libgda/providers/gda-sybase-server/Attic/gda-sybase-command.c,v
retrieving revision 1.7
diff -u -u -r1.7 gda-sybase-command.c
--- gda-sybase-command.c 2001/07/18 23:05:42 1.7
+++ gda-sybase-command.c 2001/11/22 04:42:44
@@ -72,283 +72,449 @@
gboolean
gda_sybase_command_new (GdaServerCommand * cmd)
{
- GdaServerConnection *cnc = NULL;
- sybase_Command *scmd = NULL;
- sybase_Connection *scnc = NULL;
-
- g_return_val_if_fail (cmd != NULL, FALSE);
- cnc = gda_server_command_get_connection (cmd);
- g_return_val_if_fail (cnc != NULL, FALSE);
- scnc = (sybase_Connection *)
- gda_server_connection_get_user_data (cnc);
- g_return_val_if_fail (scnc != NULL, FALSE);
- // FIXME: Reopen connection if this sanity check fails
- g_return_val_if_fail (scnc->cnc != NULL, FALSE);
-
- // Allocate command userdata
- scmd = g_new0 (sybase_Command, 1);
- g_return_val_if_fail (scmd != NULL, FALSE);
-
- scmd->cmd = (CS_COMMAND *) NULL;
-
- if (SYB_CHK
- ((CS_INT *) & scnc->ret, ct_cmd_alloc (scnc->cnc, &scmd->cmd),
- NULL, NULL, cnc, NULL) != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret,
- "Could not allocate " "cmd structure\n");
- g_free ((gpointer) scmd);
- return FALSE;
- }
- gda_server_command_set_user_data (cmd, (gpointer) scmd);
-
- return TRUE;
+ GdaServerConnection *cnc = NULL;
+ sybase_Command *scmd = NULL;
+ sybase_Connection *scnc = NULL;
+ CS_RETCODE ret;
+
+ g_return_val_if_fail (cmd != NULL, FALSE);
+ cnc = gda_server_command_get_connection (cmd);
+ g_return_val_if_fail (cnc != NULL, FALSE);
+ scnc = (sybase_Connection *)
+ gda_server_connection_get_user_data (cnc);
+ g_return_val_if_fail (scnc != NULL, FALSE);
+ // FIXME: Reopen connection if this sanity check fails
+ g_return_val_if_fail (scnc->cnc != NULL, FALSE);
+
+ // Allocate command userdata
+ scmd = g_new0 (sybase_Command, 1);
+ g_return_val_if_fail (scmd != NULL, FALSE);
+
+ scmd->cmd = (CS_COMMAND *) NULL;
+
+ /* if (SYB_CHK */
+ /* ((CS_INT *) & scnc->ret, ct_cmd_alloc (scnc->cnc, &scmd->cmd), */
+ /* NULL, NULL, cnc, NULL) != CS_SUCCEED) */
+ /* { */
+ /* gda_sybase_cleanup (scnc, scnc->ret, */
+ /* "Could not allocate " "cmd structure\n"); */
+ /* g_free ((gpointer) scmd); */
+ /* return FALSE; */
+ /* } */
+
+ ret = ct_cmd_alloc (scnc->cnc,
+ &scmd->cmd);
+ if (ret != CS_SUCCEED)
+ {
+ /* it failed, check the server messages */
+ sybase_chkerr(NULL,NULL,cnc,cmd,__PRETTY_FUNCTION__);
+ return (FALSE);
+ }
+ gda_server_command_set_user_data (cmd, (gpointer) scmd);
+ return TRUE;
}
GdaServerRecordset *
gda_sybase_command_execute (GdaServerCommand * cmd,
- GdaError * error,
- const GDA_CmdParameterSeq * params,
- gulong * affected, gulong options)
+ GdaError * error,
+ const GDA_CmdParameterSeq * params,
+ gulong * affected,
+ gulong options)
{
- GdaServerConnection *cnc = NULL;
- GdaServerRecordset *recset = NULL;
- sybase_Connection *scnc = NULL;
- sybase_Command *scmd = NULL;
- sybase_Recordset *srecset = NULL;
- gchar *sql_cmd = NULL;
- CS_INT result_type;
-
- g_return_val_if_fail (cmd != NULL, NULL);
- cnc = gda_server_command_get_connection (cmd);
- g_return_val_if_fail (cnc != NULL, NULL);
- scnc = (sybase_Connection *)
- gda_server_connection_get_user_data (cnc);
- g_return_val_if_fail (scnc != NULL, NULL);
- scmd = (sybase_Command *) gda_server_command_get_user_data (cmd);
-
- g_return_val_if_fail (scmd->cmd != NULL, NULL);
-
- sql_cmd = gda_server_command_get_text (cmd);
- g_return_val_if_fail (sql_cmd != NULL, NULL);
-
- if (gda_sybase_connection_dead (cnc)) {
-// gda_server_error_make(error, 0, cnc, "connection seems to be dead");
- gda_log_error (_("Connection seems to be dead"));
- sybase_chkerr (error, NULL, cnc, cmd, __PRETTY_FUNCTION__);
- }
+ GdaServerConnection *cnc = NULL;
+ GdaServerRecordset *recset = NULL;
+ sybase_Connection *scnc = NULL;
+ sybase_Command *scmd = NULL;
+ sybase_Recordset *srecset = NULL;
+ gchar *sql_cmd = NULL;
+ CS_INT result_type;
+ CS_RETCODE ret;
+ CS_RETCODE fetch_ret;
+ CS_INT rows_read;
+ gboolean everythingOK = TRUE;
+
+ g_return_val_if_fail (cmd != NULL, NULL);
+ cnc = gda_server_command_get_connection (cmd);
+ g_return_val_if_fail (cnc != NULL, NULL);
+ scnc = (sybase_Connection *)
+ gda_server_connection_get_user_data (cnc);
+ g_return_val_if_fail (scnc != NULL, NULL);
+ scmd = (sybase_Command *) gda_server_command_get_user_data (cmd);
+
+ g_return_val_if_fail (scmd->cmd != NULL, NULL);
+
+ sql_cmd = gda_server_command_get_text (cmd);
+ g_return_val_if_fail (sql_cmd != NULL, NULL);
+
+ /* FIXME - attempt to reopen the connection */
+ /* need to check this out... */
+ if (gda_sybase_connection_dead (cnc))
+ {
+ // gda_server_error_make(error, 0, cnc, "connection seems to be dead");
+ gda_log_error (_("Connection seems to be dead"));
+
+ /* sybase_chkerr (error, NULL, cnc, cmd, __PRETTY_FUNCTION__); */
+ }
+
#ifdef SYBASE_DEBUG
- gda_log_message (_("executing command '%s'"), sql_cmd);
+ gda_log_message (_("executing command '%s'"), sql_cmd);
#endif
- // Initialize cmd structure and send query
- if (SYB_CHK ((CS_INT *) & scnc->ret,
- ct_command (scmd->cmd, CS_LANG_CMD, sql_cmd, CS_NULLTERM,
- CS_UNUSED),
- error, NULL, cnc, cmd) != CS_SUCCEED) {
+
+
+ // Initialize cmd structure and send query
+ /* if (SYB_CHK ((CS_INT *) & scnc->ret, */
+ /* , */
+ /* error, NULL, cnc, cmd) != CS_SUCCEED) { */
// Cancel command if setting cmd structure fails
- SYB_CHK ((CS_INT *) & scnc->ret,
- ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL), error,
- NULL, cnc, cmd);
- gda_log_error (_("Filling command structure failed\n"));
- return NULL;
- }
- if (SYB_CHK ((CS_INT *) & scnc->ret, ct_send (scmd->cmd),
- error, NULL, cnc, cmd) != CS_SUCCEED) {
- // Cancel command if sending command fails
- SYB_CHK ((CS_INT *) & scnc->ret,
- ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL), error,
- NULL, cnc, cmd);
- gda_log_error (_("sending cmd failed"));
- return NULL;
- }
-
- // Create a new recordset
- recset = gda_server_recordset_new (cnc);
- if (!recset) {
- gda_log_error (_("Allocating recordset failed"));
- SYB_CHK ((CS_INT *) & scnc->ret,
- ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL), error,
- NULL, cnc, cmd);
- return NULL;
- }
- srecset =
- (sybase_Recordset *)
- gda_server_recordset_get_user_data (recset);
-
- if (!srecset) {
- gda_server_recordset_free (recset);
- gda_log_error (_("Getting recordset userdata failed"));
- SYB_CHK ((CS_INT *) & scnc->ret,
- ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL), error,
- NULL, cnc, cmd);
- return NULL;
- }
-
- // initialize recordset
- srecset->cnc = cnc;
- srecset->cmd = cmd;
- srecset->scnc = scnc;
- srecset->scmd = scmd;
-
- /* Fetching results is a bit tricky,
- because sybase can have multiple result types outstanding on one query.
- If we do not fetch all results, the command structure having results
- blocks the connection (i.e. all commands using the same connection).
- If we want to cleanly perform the query, we'd need to either hack
- the ct_results loop into gda_sybase_recordset_move_next func
- or proceed the results within here, storing the result data redundant
- in srecset. In 2nd case, we'd have resultdata at least twice in memory.
- On the other hand, we could return a correct affected result, because+
- sybase just can return a CS_ROW_COUNT after all rows have been fetched.
-
- We have to keep our eyes on recset pointer we return, though.
- At the moment, we try to just fetch the row results and first cursor
- results, which is not clean, but saves memory:
- 1. switch ct_results
- 2. if row/cursor result: init recordset(ct_res_info/ct_bind)
- if succeed: return recordset
- 3. gda will ct_fetch result using gda_sybase_recordset_move_next()
- If anything fails or is unknown, ct_cancel all results of current cmd
- */
- while (SYB_CHK
- ((CS_INT *) & scnc->ret, ct_results (scmd->cmd, &result_type),
- error, recset, cnc, cmd) == CS_SUCCEED) {
- srecset->ret = result_type;
-
- switch ((int) result_type) {
- case CS_ROW_RESULT:
- case CS_CURSOR_RESULT:
- gda_sybase_init_recset_fields (error, recset, srecset,
- result_type);
- if (recset) {
- if (affected) {
- *affected = srecset->rows_cnt;
+ /* SYB_CHK ((CS_INT *) & scnc->ret, */
+
+ /* NULL, cnc, cmd); */
+ /* gda_log_error (_("Filling command structure failed\n")); */
+ /* return NULL; */
+ /* } */
+
+
+
+ gda_sybase_debug_msg("about to ct_command");
+
+
+ ret = ct_command (scmd->cmd,
+ CS_LANG_CMD,
+ sql_cmd,
+ CS_NULLTERM,
+ CS_UNUSED);
+ if (ret != CS_SUCCEED)
+ {
+ /* it failed, check the server messages */
+ sybase_chkerr(error,recset,cnc,cmd,__PRETTY_FUNCTION__);
+ ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL);
+ /* see if there are any error messages after the ct_cancel*/
+ /* call */
+ sybase_chkerr(error,recset,cnc,cmd,__PRETTY_FUNCTION__) ;
+ return (NULL);
}
- return recset;
- }
- else {
- SYB_CHK ((CS_INT *) & scnc->ret,
- ct_cancel (NULL, scmd->cmd,
- CS_CANCEL_ALL), error,
- recset, cnc, cmd);
- return NULL;
- }
- break;
- case CS_CMD_DONE:
-#ifdef SYBASE_DEBUG
- gda_log_message (_
- ("Command execution finished, all results processed"));
-#endif
- break;
- case CS_CMD_FAIL:
- gda_log_error (_("Command failed"));
- break;
- case CS_CMD_SUCCEED:
-#ifdef SYBASE_DEBUG
- gda_log_message (_
- ("Execution of resultless command succeeded"));
-#endif
- break;
- case CS_COMPUTE_RESULT:
- case CS_STATUS_RESULT:
- case CS_COMPUTEFMT_RESULT:
- case CS_MSG_RESULT:
- case CS_ROWFMT_RESULT:
- case CS_DESCRIBE_RESULT:
- default:
- // We cancel any other cmd
- if (srecset && !srecset->data) {
- ct_cancel (NULL, scmd->cmd,
- CS_CANCEL_CURRENT);
- }
- else {
- ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL);
- }
- gda_log_message (_("ct_results() returned %x"),
- result_type);
- break;
- }
- }
+ gda_sybase_debug_msg("just after ct_command ");
- // Check if we succeeded
- switch ((int) scnc->ret) {
- case CS_END_RESULTS:
-#ifdef SYBASE_DEBUG
- gda_log_message (_
- ("No further results, command completly succeeded."));
-#endif
- break;
- case CS_FAIL:
- gda_log_error (_
- ("An error occured during command execution."));
- SYB_CHK ((CS_INT *) & scnc->ret,
- ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL), error,
- recset, cnc, cmd);
- break;
- default:
- gda_log_error (_("Cmd execution returned unknown result, "
- "may be an error"));
- SYB_CHK ((CS_INT *) & scnc->ret,
- ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL),
- error, recset, cnc, cmd);
- break;
- }
-
- // Did we initialize any data in sybase_Recordset?
- // If not, we can free the recordset
- if (srecset && !srecset->data) {
-#ifdef SYBASE_DEBUG
- gda_log_message (_
- ("No data returned, freeing recordset structure"));
-#endif
- gda_server_recordset_free (recset);
- recset = NULL;
- }
+
+
+ /* if (SYB_CHK ((CS_INT *) & scnc->ret, ct_send (scmd->cmd), */
+ /* error, NULL, cnc, cmd) != CS_SUCCEED) { */
+ /* // Cancel command if sending command fails */
+ /* SYB_CHK ((CS_INT *) & scnc->ret, */
+ /* ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL), error, */
+ /* NULL, cnc, cmd); */
+ /* gda_log_error (_("sending cmd failed")); */
+ /* return NULL; */
+ /* } */
+
+
+
+ ret = ct_send (scmd->cmd);
+
+ sybase_chkerr(error,recset,cnc,cmd,__PRETTY_FUNCTION__);
+
+ if (ret != CS_SUCCEED)
+ {
+ /* it failed, check the server messages */
+ sybase_chkerr(error,recset,cnc,cmd,__PRETTY_FUNCTION__);
+ ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL);
+ /* see if there are any error messages after the ct_cancel*/
+ /* call */
+ sybase_chkerr(error,recset,cnc,cmd,__PRETTY_FUNCTION__);
+ return (NULL);
+ }
+
+ gda_sybase_debug_msg("after ct_send ");
+
+
+
+ // Create a new recordset
+ recset = gda_server_recordset_new (cnc);
+ if (!recset)
+ {
+ gda_log_error (_("Allocating recordset failed"));
+
+ /* SYB_CHK ((CS_INT *) & scnc->ret, */
+ /* ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL), error, */
+ /* NULL, cnc, cmd); */
+ ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL);
+ /* see if there are any error messages after the ct_cancel*/
+ /* call */
+ sybase_chkerr(error,recset,cnc,cmd,__PRETTY_FUNCTION__);
+ return (NULL);
+ }
+ srecset =
+ (sybase_Recordset *)
+ gda_server_recordset_get_user_data (recset);
+
+ if (!srecset)
+ {
+ gda_server_recordset_free (recset);
+ gda_log_error (_("Getting recordset userdata failed"));
+
+ /* SYB_CHK ((CS_INT *) & scnc->ret, */
+ /* ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL), error, */
+ /* NULL, cnc, cmd); */
+
+ ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL);
+ /* see if there are any error messages after the ct_cancel*/
+ /* call */
+ sybase_chkerr(error,recset,cnc,cmd,__PRETTY_FUNCTION__);
+ return NULL;
+ }
+
+
+ /* initialize this value, in case the query does not have any results*/
+
+ affected = 0;
+ srecset->recordSetRowStatus = SYBASE_NO_DATA_RETURNED;
- return recset;
+ // initialize recordset
+ srecset->cnc = cnc;
+ srecset->cmd = cmd;
+ srecset->scnc = scnc;
+ srecset->scmd = scmd;
+
+
+ /* Fetching results is a bit tricky,
+ because sybase can have multiple result types outstanding on one query.
+ If we do not fetch all results, the command structure having results
+ blocks the connection (i.e. all commands using the same connection).
+ If we want to cleanly perform the query, we'd need to either hack
+ the ct_results loop into gda_sybase_recordset_move_next func
+ or proceed the results within here, storing the result data redundant
+ in srecset. In 2nd case, we'd have resultdata at least twice in memory.
+ On the other hand, we could return a correct affected result, because+
+ sybase just can return a CS_ROW_COUNT after all rows have been fetched.
+
+ We have to keep our eyes on recset pointer we return, though.
+ At the moment, we try to just fetch the row results and first cursor
+ results, which is not clean, but saves memory:
+ 1. switch ct_results
+ 2. if row/cursor result: init recordset(ct_res_info/ct_bind)
+ if succeed: return recordset
+ 3. gda will ct_fetch result using gda_sybase_recordset_move_next()
+ If anything fails or is unknown, ct_cancel all results of current cmd
+ */
+
+
+
+ /* while (SYB_CHK */
+ /* ((CS_INT *) & scnc->ret, ct_results (scmd->cmd, &result_type), */
+ /* error, recset, cnc, cmd) == CS_SUCCEED) { */
+
+
+ gda_sybase_debug_msg("just before ct_results ");
+
+ scnc->ret = ct_results (scmd->cmd, &result_type);
+
+ sybase_chkerr(error,recset,cnc,cmd,__PRETTY_FUNCTION__);
+
+ gda_sybase_debug_msg("just after ct_results ");
+
+ while (scnc->ret == CS_SUCCEED)
+ {
+ srecset->ret = result_type;
+
+ switch ((int) result_type) {
+ case CS_ROW_RESULT:
+ case CS_CURSOR_RESULT:
+
+ srecset->recordSetRowStatus = SYBASE_DATA_RETURNED;
+
+ gda_sybase_debug_msg("about to init fields");
+
+ gda_sybase_init_recset_fields (error,
+ recset,
+ srecset,
+ result_type,
+ cnc);
+ if (recset)
+ {
+ if (affected)
+ {
+ *affected = srecset->rows_cnt;
+ }
+ return recset;
+ }
+ else
+ {
+ ret = ct_cancel(NULL, scmd->cmd,CS_CANCEL_ALL);
+ sybase_chkerr(error,recset,cnc,cmd,__PRETTY_FUNCTION__);
+
+ return NULL;
+ }
+ break;
+ case CS_CMD_DONE:
+
+ gda_sybase_debug_msg("CS_CMD_DONE");
+
+ break;
+ case CS_CMD_FAIL:
+
+ gda_sybase_debug_msg("CS_CMD_FAIL");
+
+ everythingOK = FALSE;
+
+ break;
+ case CS_CMD_SUCCEED:
+ gda_sybase_debug_msg("CS_CMD_SUCCEED");
+
+ break;
+
+ /* FIXME mike - figure out how to handle this stuff... */
+ /* on any of these result types, cancel the command */
+ case CS_COMPUTE_RESULT:
+ gda_sybase_debug_msg("CS_COMPUTE_RESULT");
+ case CS_STATUS_RESULT:
+ gda_sybase_debug_msg("CS_STATUS_RESULT");
+ case CS_COMPUTEFMT_RESULT:
+ gda_sybase_debug_msg("CS_COMPUTEFMT_RESULT");
+ case CS_MSG_RESULT:
+ gda_sybase_debug_msg("CS_MSG_RESULT");
+ case CS_ROWFMT_RESULT:
+ gda_sybase_debug_msg("CS_ROWFMT_RESULT");
+ case CS_DESCRIBE_RESULT:
+ gda_sybase_debug_msg("CS_DESCRIBE_RESULT");
+ default:
+ gda_sybase_debug_msg("DEFAULT, BABY in ct_results loop");
+
+ // We cancel any other cmd
+ if (srecset && !srecset->data) {
+ ct_cancel (NULL, scmd->cmd,
+ CS_CANCEL_CURRENT);
+
+ }
+ else {
+ ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL);
+ }
+ gda_log_message (_("ct_results() returned %x"),
+ result_type);
+ break;
+
+ }
+ scnc->ret = ct_results (scmd->cmd, &result_type);
+
+ /* if it failed, check the server messages */
+ if (scnc->ret == CS_FAIL)
+ {
+ gda_sybase_debug_msg("inside the ct_results loop, there was a bad");
+
+ sybase_chkerr(error,recset,cnc,cmd,__PRETTY_FUNCTION__);
+ }
+ }
+
+
+ if (!everythingOK)
+ {
+ gda_server_recordset_free (recset);
+ recset = NULL;
+ }
+ else
+ {
+ gda_sybase_debug_msg("after ct_results, everything ok");
+ }
+
+
+ // Check if we succeeded
+/* switch ((int) scnc->ret) */
+/* { */
+/* case CS_END_RESULTS: */
+
+/* gda_sybase_debug_msg("CS_END_RESULTS after ct_results"); */
+
+/* break; */
+/* case CS_FAIL: */
+
+/* ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL); */
+/* sybase_chkerr(error,recset,cnc,cmd,__PRETTY_FUNCTION__); */
+/* gda_server_recordset_free (recset); */
+/* recset = NULL; */
+/* break; */
+/* default: */
+/* gda_log_error (_("Cmd execution returned unknown result, " */
+/* "may be an error")); */
+
+/* ct_cancel (NULL, scmd->cmd, CS_CANCEL_ALL); */
+/* sybase_chkerr(error,recset,cnc,cmd,__PRETTY_FUNCTION__); */
+/* gda_server_recordset_free (recset); */
+/* recset = NULL; */
+/* break; */
+/* } */
+
+
+ if (srecset && !srecset->data &&
+ srecset->recordSetRowStatus == SYBASE_DATA_RETURNED)
+ {
+
+ gda_sybase_debug_msg("no data, free the recordset");
+
+ gda_server_recordset_free (recset);
+ recset = NULL;
+ }
+
+ return recset;
}
void
gda_sybase_command_free (GdaServerCommand * cmd)
{
- GdaServerConnection *cnc = NULL;
- sybase_Connection *scnc = NULL;
- sybase_Command *scmd = NULL;
-
- g_return_if_fail (cmd != NULL);
- cnc = gda_server_command_get_connection (cmd);
- if (cnc) {
- scnc = (sybase_Connection *)
- gda_server_connection_get_user_data (cnc);
- }
- scmd = (sybase_Command *) gda_server_command_get_user_data (cmd);
-
- // Be careful: We have not checked any pointer so far because we want to
- // free any cmd structure
- if (scmd && scnc) {
- if (scmd->cmd) {
- if (SYB_CHK
- ((CS_INT *) & scnc->ret, ct_cmd_drop (scmd->cmd),
- NULL, NULL, cnc, cmd) != CS_SUCCEED) {
- gda_log_error (_
- ("Freeing command structure failed"));
- }
- }
- g_free ((gpointer) scmd);
- gda_server_command_set_user_data (cmd, (gpointer) NULL);
- }
- else if (scmd && !scnc) {
- if (scmd->cmd) {
- if (SYB_CHK (NULL,
- ct_cmd_drop (scmd->cmd),
- NULL, NULL, cnc, cmd) != CS_SUCCEED) {
- gda_log_error (_
- ("Freeing command structure failed"));
- }
+ GdaServerConnection *cnc = NULL;
+ sybase_Connection *scnc = NULL;
+ sybase_Command *scmd = NULL;
+ CS_RETCODE ret;
+
+ g_return_if_fail (cmd != NULL);
+ cnc = gda_server_command_get_connection (cmd);
+ if (cnc) {
+ scnc = (sybase_Connection *)
+ gda_server_connection_get_user_data (cnc);
}
- g_free ((gpointer) scmd);
- gda_server_command_set_user_data (cmd, (gpointer) NULL);
- } // else would be we have no command userdata and hence nothing to free
+ scmd = (sybase_Command *) gda_server_command_get_user_data (cmd);
+
+ /* Be careful: We have not checked any pointer so far because we want to */
+ /* free any cmd structure */
+ if (scmd && scnc)
+ {
+ if (scmd->cmd)
+ {
+
+ /* if (SYB_CHK */
+ /* ((CS_INT *) & scnc->ret, ct_cmd_drop (scmd->cmd), */
+ /* NULL, NULL, cnc, cmd) != CS_SUCCEED) { */
+ ret = ct_cmd_drop (scmd->cmd);
+
+ if (ret != CS_SUCCEED)
+ {
+ sybase_chkerr(NULL,NULL,cnc,cmd,__PRETTY_FUNCTION__);
+ gda_log_error (_("Freeing command structure failed"));
+ }
+ }
+ g_free ((gpointer) scmd);
+ gda_server_command_set_user_data (cmd, (gpointer) NULL);
+ }
+
+ /* this is a wierd situation for openclient to have a command */
+ /* structure be valid w/o a connection struct. we can't check */
+ /* the server messages w/o a connectoin stucture */
+ else if (scmd && !scnc)
+ {
+ if (scmd->cmd)
+ {
+ ret = ct_cmd_drop (scmd->cmd);
+
+ if (ret != CS_SUCCEED)
+ {
+ /* if (SYB_CHK (NULL, */
+ /* ct_cmd_drop (scmd->cmd), */
+ /* NULL, NULL, cnc, cmd) != CS_SUCCEED) { */
+ gda_log_error (_("Freeing command structure failed"));
+ }
+ }
+ g_free ((gpointer) scmd);
+ gda_server_command_set_user_data (cmd, (gpointer) NULL);
+ } /* else would be we have no command userdata and hence nothing to free */
}
Index: gda-sybase-command.h
===================================================================
RCS file: /cvs/gnome/libgda/providers/gda-sybase-server/Attic/gda-sybase-command.h,v
retrieving revision 1.3.4.1
diff -u -u -r1.3.4.1 gda-sybase-command.h
--- gda-sybase-command.h 2001/09/16 20:12:39 1.3.4.1
+++ gda-sybase-command.h 2001/11/22 04:42:44
@@ -1,58 +1,58 @@
-/*
- * $Id: gda-sybase-command.h,v 1.3.4.1 2001/09/16 20:12:39 rodrigo Exp $
- *
- * GNOME DB sybase Provider
- * Copyright (C) 2000 Rodrigo Moya
- * Copyright (C) 2000 Stephan Heinze
- * Copyright (C) 2000 Holger Thon
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#if !defined(__gda_sybase_command_h__)
-# define __gda_sybase_command_h__
-
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-
-#include <gda-server.h>
-#include <glib.h>
-#include <ctpublic.h>
-#include "gda-sybase.h"
-
-/*
- * Per-object specific structures
- */
-
-typedef struct _sybase_Command
-{
- CS_COMMAND *cmd;
-}
-sybase_Command;
-
-/*
- * Server implementation prototypes
- */
-
-gboolean gda_sybase_command_new (GdaServerCommand * cmd);
-GdaServerRecordset *gda_sybase_command_execute (GdaServerCommand * cmd,
- GdaError * error,
- const GDA_CmdParameterSeq *
- params, gulong * affected,
- gulong options);
-void gda_sybase_command_free (GdaServerCommand * cmd);
-
-#endif
+/*
+ * $Id: gda-sybase-command.h,v 1.3.4.1 2001/09/16 20:12:39 rodrigo Exp $
+ *
+ * GNOME DB sybase Provider
+ * Copyright (C) 2000 Rodrigo Moya
+ * Copyright (C) 2000 Stephan Heinze
+ * Copyright (C) 2000 Holger Thon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#if !defined(__gda_sybase_command_h__)
+# define __gda_sybase_command_h__
+
+#if defined(HAVE_CONFIG_H)
+# include <config.h>
+#endif
+
+#include <gda-server.h>
+#include <glib.h>
+#include <ctpublic.h>
+#include "gda-sybase.h"
+
+/*
+ * Per-object specific structures
+ */
+
+typedef struct _sybase_Command
+{
+ CS_COMMAND *cmd;
+}
+sybase_Command;
+
+/*
+ * Server implementation prototypes
+ */
+
+gboolean gda_sybase_command_new (GdaServerCommand * cmd);
+GdaServerRecordset *gda_sybase_command_execute (GdaServerCommand * cmd,
+ GdaError * error,
+ const GDA_CmdParameterSeq *
+ params, gulong * affected,
+ gulong options);
+void gda_sybase_command_free (GdaServerCommand * cmd);
+
+#endif
Index: gda-sybase-connection.c
===================================================================
RCS file: /cvs/gnome/libgda/providers/gda-sybase-server/Attic/gda-sybase-connection.c,v
retrieving revision 1.11.4.1
diff -u -u -r1.11.4.1 gda-sybase-connection.c
--- gda-sybase-connection.c 2001/09/16 20:12:39 1.11.4.1
+++ gda-sybase-connection.c 2001/11/22 04:42:47
@@ -182,8 +182,9 @@
gint
gda_sybase_connection_open (GdaServerConnection * cnc,
- const gchar * dsn,
- const gchar * user, const gchar * passwd)
+ const gchar * dsn,
+ const gchar * user,
+ const gchar * passwd)
{
sybase_Connection *scnc = NULL;
@@ -208,6 +209,7 @@
gda_sybase_connection_close (GdaServerConnection * cnc)
{
sybase_Connection *scnc;
+ CS_RETCODE ret;
g_return_if_fail (cnc != NULL);
scnc = (sybase_Connection *)
@@ -215,39 +217,54 @@
g_return_if_fail (scnc != NULL);
// Close connection
- if (scnc->cnc) {
- if (SYB_CHK
- ((CS_INT *) & scnc->ret, ct_close (scnc->cnc, CS_UNUSED),
- NULL, NULL, cnc, NULL) != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret,
- "Could not close connection\n");
- return;
- }
- if (SYB_CHK ((CS_INT *) & scnc->ret, ct_con_drop (scnc->cnc),
- NULL, NULL, cnc, NULL) != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret,
- "Could not drop connection structure\n");
- return;
- }
- scnc->cnc = (CS_CONNECTION *) NULL;
- }
-
- if (scnc->ctx) {
- // Exit client library and drop context structure
- if ((scnc->ret =
- ct_exit (scnc->ctx, CS_UNUSED)) != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret,
- "ct_exit failed");
- return;
- }
-
- if ((scnc->ret = cs_ctx_drop (scnc->ctx)) != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret,
- "cs_ctx_drop failed");
- return;
- }
- scnc->ctx = (CS_CONTEXT *) NULL;
- }
+ if (scnc->cnc)
+ {
+/* if (SYB_CHK */
+/* ((CS_INT *) & scnc->ret, ct_close (scnc->cnc, CS_UNUSED), */
+/* NULL, NULL, cnc, NULL) != CS_SUCCEED) { */
+
+ ret = ct_close(scnc->cnc, CS_UNUSED);
+ if (ret != CS_SUCCEED)
+ {
+ sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__);
+ gda_sybase_cleanup (scnc, scnc->ret,
+ "Could not close connection\n");
+ return;
+ }
+
+/* if (SYB_CHK ((CS_INT *) & scnc->ret, ct_con_drop (scnc->cnc), */
+/* NULL, NULL, cnc, NULL) != CS_SUCCEED) { */
+ ret = ct_con_drop (scnc->cnc);
+ if (ret != CS_SUCCEED)
+ {
+ sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__);
+ gda_sybase_cleanup (scnc, scnc->ret,
+ "Could not drop connection structure\n");
+ return;
+ }
+ scnc->cnc = (CS_CONNECTION *) NULL;
+ }
+ if (scnc->ctx)
+ {
+ // Exit client library and drop context structure
+ if ((scnc->ret =
+ ct_exit (scnc->ctx, CS_UNUSED)) != CS_SUCCEED)
+ {
+ sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__);
+ gda_sybase_cleanup (scnc, scnc->ret,
+ "ct_exit failed");
+ return;
+ }
+
+ if ((scnc->ret = cs_ctx_drop (scnc->ctx)) != CS_SUCCEED)
+ {
+ sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__);
+ gda_sybase_cleanup (scnc, scnc->ret,
+ "cs_ctx_drop failed");
+ return;
+ }
+ scnc->ctx = (CS_CONTEXT *) NULL;
+ }
}
gint
@@ -333,17 +350,17 @@
switch (feature) {
case GDA_Connection_FEATURE_SQL:
- return TRUE;
case GDA_Connection_FEATURE_FOREIGN_KEYS:
- case GDA_Connection_FEATURE_INHERITANCE:
- case GDA_Connection_FEATURE_OBJECT_ID:
case GDA_Connection_FEATURE_PROCS:
- case GDA_Connection_FEATURE_SEQUENCES:
case GDA_Connection_FEATURE_SQL_SUBSELECT:
case GDA_Connection_FEATURE_TRANSACTIONS:
case GDA_Connection_FEATURE_TRIGGERS:
case GDA_Connection_FEATURE_VIEWS:
+ return TRUE;
case GDA_Connection_FEATURE_XML_QUERIES:
+ case GDA_Connection_FEATURE_INHERITANCE:
+ case GDA_Connection_FEATURE_OBJECT_ID:
+ case GDA_Connection_FEATURE_SEQUENCES:
default:
return FALSE;
}
@@ -414,15 +431,17 @@
// we do not touch CS_* variables and *_diag variables,
// as they are essential for the connection
- scnc->serr.err_type = SYBASE_ERR_NONE;
+/* scnc->serr.err_type = SYBASE_ERR_NONE; */
if (force_set_null_pointers) {
- scnc->serr.udeferr_msg = (gchar *) NULL;
- scnc->database = (gchar *) NULL;
+
+/* scnc->serr.udeferr_msg = (gchar *) NULL; */
+ scnc->serr.eMessage = (gchar *) NULL;
+ scnc->database = (gchar *) NULL;
}
else {
- if (scnc->serr.udeferr_msg) {
- g_free ((gpointer) scnc->serr.udeferr_msg);
- }
+/* if (scnc->serr.udeferr_msg) { */
+/* g_free ((gpointer) scnc->serr.udeferr_msg); */
+/* } */
if (scnc->database) {
g_free ((gpointer) scnc->database);
}
@@ -797,6 +816,8 @@
CS_BYTE *mempool;
CS_INT memsize = 131072;
gchar *dsn;
+ CS_RETCODE ret;
+
// At least we need valid connection structs
g_return_val_if_fail (cnc != NULL, FALSE);
@@ -819,31 +840,36 @@
////////////////////////////////////////////////////////
// Create context info and initialize ctlib
+
if ((scnc->ret =
cs_ctx_alloc (CS_VERSION_100, &scnc->ctx)) != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret,
- "Could not allocate context");
- return FALSE;
+ gda_sybase_cleanup (scnc, scnc->ret,
+ "Could not allocate context");
+ return FALSE;
}
+
+
+
if ((scnc->ret = ct_init (scnc->ctx, CS_VERSION_100)) != CS_SUCCEED) {
gda_sybase_cleanup (scnc, scnc->ret,
"Could not initialize client library");
return FALSE;
}
- mempool = (CS_BYTE *) g_new0 (CS_BYTE, memsize);
- if (!mempool) {
- gda_sybase_cleanup (scnc, scnc->ret,
- "Could not allocate mempool");
- return FALSE;
- }
- if ((scnc->ret = ct_config (scnc->ctx, CS_SET, CS_MEM_POOL,
- mempool, memsize, NULL)) != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret,
- "Could not initialize mempool");
- g_free ((gpointer) mempool);
- return FALSE;
- }
+/* mempool = (CS_BYTE *) g_new0 (CS_BYTE, memsize); */
+/* if (!mempool) { */
+/* gda_sybase_cleanup (scnc, scnc->ret, */
+/* "Could not allocate mempool"); */
+/* return FALSE; */
+/* } */
+/* if ((scnc->ret = ct_config (scnc->ctx, CS_SET, CS_MEM_POOL, */
+/* mempool, memsize, NULL)) != CS_SUCCEED) { */
+/* gda_sybase_cleanup (scnc, scnc->ret, */
+/* "Could not initialize mempool"); */
+/* g_free ((gpointer) mempool); */
+/* return FALSE; */
+/* } */
+
// locales must be set up before we have any connection,
// so get dsn and initialize locale if given
dsn = gda_server_connection_get_dsn (cnc);
@@ -874,6 +900,7 @@
return FALSE;
}
+ /* this is for callbacks... */
/*
if (gda_sybase_install_error_handlers(cnc) != 0) {
return FALSE;
@@ -882,35 +909,72 @@
// We go on proceeding connection properties and dsn arguments
// set up application name, username and password
- if (SYB_CHK ((CS_INT *) & scnc->ret,
- ct_con_props (scnc->cnc, CS_SET, CS_APPNAME,
- (CS_CHAR *) GDA_SYBASE_DEFAULT_APPNAME,
- CS_NULLTERM, NULL),
- NULL, NULL, cnc, NULL) != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret,
- "Could not set application name");
- return FALSE;
- }
- if (SYB_CHK ((CS_INT *) & scnc->ret,
- ct_con_props (scnc->cnc, CS_SET, CS_USERNAME,
- (CS_CHAR *)
- gda_server_connection_get_username (cnc),
- CS_NULLTERM, NULL), NULL, NULL, cnc,
- NULL) != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret,
- "Could not set user name");
- return FALSE;
- }
- if (SYB_CHK ((CS_INT *) & scnc->ret,
- ct_con_props (scnc->cnc, CS_SET, CS_PASSWORD,
- (CS_CHAR *)
- gda_server_connection_get_password (cnc),
- CS_NULLTERM, NULL), NULL, NULL, cnc,
- NULL) != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret,
- "Could not set password");
- return FALSE;
- }
+
+/* if (SYB_CHK ((CS_INT *) & scnc->ret, */
+/* ct_con_props (scnc->cnc, CS_SET, CS_APPNAME, */
+/* (CS_CHAR *) GDA_SYBASE_DEFAULT_APPNAME, */
+/* CS_NULLTERM, NULL), */
+/* NULL, NULL, cnc, NULL) != CS_SUCCEED) { */
+
+ ret = ct_con_props (scnc->cnc,
+ CS_SET,
+ CS_APPNAME,
+ (CS_CHAR *) GDA_SYBASE_DEFAULT_APPNAME,
+ CS_NULLTERM,
+ NULL);
+
+ if ((ret != CS_SUCCEED) ||
+ (sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__)))
+ {
+ gda_sybase_cleanup (scnc, scnc->ret,
+ "Could not set application name");
+ return FALSE;
+ }
+
+/* if (SYB_CHK ((CS_INT *) & scnc->ret, */
+/* ct_con_props (scnc->cnc, CS_SET, CS_USERNAME, */
+/* (CS_CHAR *) */
+/* gda_server_connection_get_username (cnc), */
+/* CS_NULLTERM, NULL), NULL, NULL, cnc, */
+/* NULL) != CS_SUCCEED) { */
+
+
+ ret = ct_con_props(scnc->cnc,
+ CS_SET,
+ CS_USERNAME,
+ (CS_CHAR *)gda_server_connection_get_username (cnc),
+ CS_NULLTERM,
+ NULL);
+
+ if ((ret != CS_SUCCEED) ||
+ (sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__)))
+ {
+ gda_sybase_cleanup (scnc, scnc->ret,
+ "Could not set user name");
+ return FALSE;
+ }
+
+/* if (SYB_CHK ((CS_INT *) & scnc->ret, */
+/* ct_con_props (scnc->cnc, CS_SET, CS_PASSWORD, */
+/* (CS_CHAR *) */
+/* gda_server_connection_get_password (cnc), */
+/* CS_NULLTERM, NULL), NULL, NULL, cnc, */
+/* NULL) != CS_SUCCEED) { */
+
+ ret = ct_con_props (scnc->cnc,
+ CS_SET,
+ CS_PASSWORD,
+ (CS_CHAR *)gda_server_connection_get_password (cnc),
+ CS_NULLTERM,
+ NULL);
+ if ((ret != CS_SUCCEED)||
+ (sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__)))
+ {
+
+ gda_sybase_cleanup (scnc, scnc->ret,
+ "Could not set password");
+ return FALSE;
+ }
// Proceed further parameters given in dsn
if (((dsn = gda_server_connection_get_dsn (cnc)) != NULL) &&
@@ -919,25 +983,42 @@
}
// Connect
- if (SYB_CHK ((CS_INT *) & scnc->ret,
- ct_connect (scnc->cnc, (CS_CHAR *) NULL, 0),
- NULL, NULL, cnc, NULL) != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret,
- (first_connection == FALSE)
- ? "Could not reconnect"
- : "Could not connect");
- return FALSE;
- }
+/* if (SYB_CHK ((CS_INT *) & scnc->ret, */
+/* ct_connect (scnc->cnc, (CS_CHAR *) NULL, 0), */
+/* NULL, NULL, cnc, NULL) != CS_SUCCEED) { */
+
+ ret = ct_connect (scnc->cnc, (CS_CHAR *) NULL, 0);
+
+ if ((ret != CS_SUCCEED)||
+ (sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__)))
+ {
+
+ gda_sybase_cleanup (scnc, scnc->ret,
+ (first_connection == FALSE)
+ ? "Could not reconnect"
+ : "Could not connect");
+ return FALSE;
+ }
// To test the connection, we ask for the servers name
- if (SYB_CHK ((CS_INT *) & scnc->ret,
- ct_con_props (scnc->cnc, CS_GET, CS_SERVERNAME,
- &buf, CS_MAX_CHAR, NULL),
- NULL, NULL, cnc, NULL) != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret,
- "Could not request servername");
- return FALSE;
- }
+/* if (SYB_CHK ((CS_INT *) & scnc->ret, */
+/* ct_con_props (scnc->cnc, CS_GET, CS_SERVERNAME, */
+/* &buf, CS_MAX_CHAR, NULL), */
+/* NULL, NULL, cnc, NULL) != CS_SUCCEED) { */
+
+ ret = ct_con_props (scnc->cnc,
+ CS_GET,
+ CS_SERVERNAME,
+ &buf,
+ CS_MAX_CHAR,
+ NULL);
+ if ((ret != CS_SUCCEED)||
+ (sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__)))
+ {
+ gda_sybase_cleanup (scnc, scnc->ret,
+ "Could not request servername");
+ return FALSE;
+ }
else {
if (first_connection == FALSE)
gda_log_message (_("Reconnected to '%s'"), buf);
@@ -969,150 +1050,240 @@
gda_sybase_connection_select_database (GdaServerConnection * cnc,
const gchar * database)
{
- sybase_Connection *scnc = NULL;
- CS_COMMAND *cmd = NULL;
- gchar *sqlcmd = NULL;
- CS_INT result_type;
- gboolean okay = FALSE;
-
- g_return_val_if_fail (cnc != NULL, CS_FAIL);
- scnc = (sybase_Connection *)
- gda_server_connection_get_user_data (cnc);
- g_return_val_if_fail (scnc != NULL, CS_FAIL);
- g_return_val_if_fail (scnc->cnc != NULL, CS_FAIL);
-
- if (SYB_CHK (NULL, ct_cmd_alloc (scnc->cnc, &cmd),
- NULL, NULL, cnc, NULL) != CS_SUCCEED) {
- gda_log_error (_("%s: Could not allocate cmd structure"),
- __PRETTY_FUNCTION__);
- return CS_FAIL;
- }
-
- // Prepare cmd string
- sqlcmd = g_strdup_printf ("use %s", database);
- if (!sqlcmd) {
- gda_log_error (_
- ("%s: Could not allocate memory for cmd string"),
- __PRETTY_FUNCTION__);
- SYB_CHK (NULL, ct_cmd_drop (cmd), NULL, NULL, cnc, NULL);
- return CS_FAIL;
- }
- // Pass cmd string to CS_COMMAND structure
- if (SYB_CHK (NULL, ct_command (cmd, CS_LANG_CMD, sqlcmd, CS_NULLTERM,
- CS_UNUSED),
- NULL, NULL, cnc, NULL) != CS_SUCCEED) {
- gda_log_error (_("%s: ct_command failed"),
- __PRETTY_FUNCTION__);
+ sybase_Connection *scnc = NULL;
+ CS_COMMAND *cmd = NULL;
+ gchar *sqlcmd = NULL;
+ CS_INT result_type;
+ gboolean okay = FALSE;
+ CS_RETCODE ret;
+ CS_RETCODE ret2;
+
+ g_return_val_if_fail (cnc != NULL, CS_FAIL);
+ scnc = (sybase_Connection *)
+ gda_server_connection_get_user_data (cnc);
+ g_return_val_if_fail (scnc != NULL, CS_FAIL);
+ g_return_val_if_fail (scnc->cnc != NULL, CS_FAIL);
+
+ /* if (SYB_CHK (NULL, ct_cmd_alloc (scnc->cnc, &cmd), */
+ /* NULL, NULL, cnc, NULL) != CS_SUCCEED) { */
+
+ ret = ct_cmd_alloc (scnc->cnc, &cmd);
+ if ((ret != CS_SUCCEED)||
+ (sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__)))
+ {
+ gda_log_error (_("%s: Could not allocate cmd structure"),
+ __PRETTY_FUNCTION__);
+ return CS_FAIL;
+ }
+
+ // Prepare cmd string
+ sqlcmd = g_strdup_printf ("use %s", database);
+ if (!sqlcmd)
+ {
+ gda_log_error (_
+ ("%s: Could not allocate memory for cmd string"),
+ __PRETTY_FUNCTION__);
+
+ /* SYB_CHK (NULL, ct_cmd_drop (cmd), NULL, NULL, cnc, NULL); */
+
+ ret = ct_cmd_drop(cmd);
+ if (ret != CS_SUCCEED)
+ sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__);
+ return CS_FAIL;
+ }
+ // Pass cmd string to CS_COMMAND structure
+ /* if (SYB_CHK (NULL, ct_command (cmd, CS_LANG_CMD, sqlcmd, CS_NULLTERM, */
+ /* CS_UNUSED), */
+ /* NULL, NULL, cnc, NULL) != CS_SUCCEED) { */
+
+ ret = ct_command (cmd,
+ CS_LANG_CMD,
+ sqlcmd,
+ CS_NULLTERM,
+ CS_UNUSED);
+
+ if ((ret != CS_SUCCEED)||
+ (sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__)))
+ {
+
+ gda_log_error (_("%s: ct_command failed"),
+ __PRETTY_FUNCTION__);
+ g_free ((gpointer) sqlcmd);
+ /* SYB_CHK (NULL, ct_cmd_drop (cmd), NULL, NULL, cnc, NULL); */
+ ret = ct_cmd_drop (cmd);
+ if (ret != CS_SUCCEED)
+ sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__);
+ return CS_FAIL;
+ }
g_free ((gpointer) sqlcmd);
- SYB_CHK (NULL, ct_cmd_drop (cmd), NULL, NULL, cnc, NULL);
- return CS_FAIL;
- }
- g_free ((gpointer) sqlcmd);
-
- // Send the command
- if (SYB_CHK (NULL, ct_send (cmd), NULL, NULL, cnc, NULL) !=
- CS_SUCCEED) {
- gda_log_error (_("%s: sending command failed"),
- __PRETTY_FUNCTION__);
- SYB_CHK (NULL, ct_cmd_drop (cmd), NULL, NULL, cnc, NULL);
- return CS_FAIL;
- }
- while (CS_SUCCEED == SYB_CHK (NULL, ct_results (cmd, &result_type),
- NULL, NULL, cnc, NULL)
- ) {
- switch (result_type) {
- case CS_CMD_FAIL:
- gda_log_error (_("%s: selecting database failed"),
- __PRETTY_FUNCTION__);
- break;
- case CS_CMD_SUCCEED:
- okay = TRUE;
- break;
- default:
- break;
- }
- }
+ // Send the command
+ /* if (SYB_CHK (NULL, ct_send (cmd), NULL, NULL, cnc, NULL) != */
+ /* CS_SUCCEED) { */
+
+ ret = ct_send (cmd);
+
+ if ((ret != CS_SUCCEED)||
+ (sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__)))
+ {
+ gda_log_error (_("%s: sending command failed"),
+ __PRETTY_FUNCTION__);
+ /* SYB_CHK (NULL, ct_cmd_drop (cmd), NULL, NULL, cnc, NULL); */
+ ret = ct_cmd_drop (cmd);
+ if (ret != CS_SUCCEED)
+ sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__);
+ return CS_FAIL;
+ }
- SYB_CHK (NULL, ct_cmd_drop (cmd), NULL, NULL, cnc, NULL);
+ ret2 = ct_results (cmd, &result_type);
- if (okay) {
- return CS_SUCCEED;
- }
+ if ((ret2 != CS_SUCCEED)||
+ (sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__)))
+ {
+ ret = ct_cmd_drop (cmd);
+ sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__);
+ return CS_FAIL;
+ }
+ /* while (CS_SUCCEED == SYB_CHK (NULL, ct_results (cmd, &result_type), */
+ /* NULL, NULL, cnc, NULL) */
+ while ((ret2 == CS_SUCCEED)||(ret2 == CS_FAIL))
+ {
+ switch (result_type)
+ {
+ case CS_CMD_FAIL:
+ gda_log_error (_("%s: selecting database failed"),
+ __PRETTY_FUNCTION__);
+ break;
+ case CS_CMD_SUCCEED:
+ okay = TRUE;
+ break;
+ default:
+ break;
+ }
+ ret2 = ct_results (cmd, &result_type);
+ sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__);
+ }
+
+ /* SYB_CHK (NULL, ct_cmd_drop (cmd), NULL, NULL, cnc, NULL); */
+
+ if ((okay) && (!sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__)))
+ {
+ return CS_SUCCEED;
+ }
- gda_log_error (_("%s: use command failed"), __PRETTY_FUNCTION__);
- return CS_FAIL;
+ gda_log_error (_("%s: use command failed"), __PRETTY_FUNCTION__);
+ return CS_FAIL;
}
// Select locale for connection; we just need a CS_CONTEXT at this time
static gboolean
gda_sybase_set_locale (GdaServerConnection * cnc, const gchar * dsn)
{
- sybase_Connection *scnc;
- CS_LOCALE *locale;
- CS_RETCODE ret = CS_FAIL;
- gchar *targ_locale = NULL;
+ sybase_Connection *scnc;
+ CS_LOCALE *locale;
+ CS_RETCODE ret = CS_FAIL;
+ gchar *targ_locale = NULL;
+
+ g_return_val_if_fail (cnc != NULL, FALSE);
+ scnc = (sybase_Connection *)
+ gda_server_connection_get_user_data (cnc);
+ g_return_val_if_fail (scnc != NULL, FALSE);
+ g_return_val_if_fail (scnc->ctx != NULL, FALSE);
- g_return_val_if_fail (cnc != NULL, FALSE);
- scnc = (sybase_Connection *)
- gda_server_connection_get_user_data (cnc);
- g_return_val_if_fail (scnc != NULL, FALSE);
- g_return_val_if_fail (scnc->ctx != NULL, FALSE);
-
- if ((targ_locale = get_option (dsn, "LOCALE=")) == NULL) {
- return TRUE;
- }
+ if ((targ_locale = get_option (dsn, "LOCALE=")) == NULL) {
+ return TRUE;
+ }
#ifdef SYBASE_DEBUG
- gda_log_message ("locale = '%s'", targ_locale);
+ gda_log_message ("locale = '%s'", targ_locale);
#endif
- if ((ret = cs_loc_alloc (scnc->ctx, &locale)) != CS_SUCCEED) {
- gda_log_error (_("Could not allocate locale structure"));
- return FALSE;
- }
- if ((ret = cs_locale (scnc->ctx, CS_SET, locale, CS_LC_ALL,
- (CS_CHAR *) targ_locale, CS_NULLTERM, NULL))
- != CS_SUCCEED) {
- gda_log_error (_("Could not set locale to '%s'"),
- targ_locale);
- cs_loc_drop (scnc->ctx, locale);
- return FALSE;
- }
- if ((ret = cs_config (scnc->ctx, CS_SET, CS_LOC_PROP, locale,
- CS_UNUSED, NULL)) != CS_SUCCEED) {
- gda_log_error (_("Could not configure locale to be '%s'"),
- targ_locale);
- cs_loc_drop (scnc->ctx, locale);
- return FALSE;
- }
- if ((ret = cs_loc_drop (scnc->ctx, locale)) != CS_SUCCEED) {
- gda_log_error (_("Could not drop locale structure"));
- return FALSE;
- }
- gda_log_message ("Selected locale '%s'", targ_locale);
- return TRUE;
+/* if (((ret = cs_loc_alloc (scnc->ctx, &locale)) != CS_SUCCEED)|| */
+/* (sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__))) */
+
+ ret = cs_loc_alloc (scnc->ctx, &locale);
+ if ((ret != CS_SUCCEED)||
+ (sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__)))
+ {
+ gda_log_error (_("Could not allocate locale structure"));
+ return FALSE;
+ }
+
+/* if ((ret = cs_locale (scnc->ctx, CS_SET, locale, CS_LC_ALL, */
+/* (CS_CHAR *) targ_locale, CS_NULLTERM, NULL)) */
+/* != CS_SUCCEED) { */
+
+ ret = cs_locale (scnc->ctx,
+ CS_SET,
+ locale,
+ CS_LC_ALL,
+ (CS_CHAR *) targ_locale,
+ CS_NULLTERM,
+ NULL);
+
+ if ((ret != CS_SUCCEED)||
+ (sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__)))
+ {
+ gda_log_error (_("Could not set locale to '%s'"),
+ targ_locale);
+ cs_loc_drop (scnc->ctx, locale);
+ return FALSE;
+ }
+
+
+/* if ((ret = cs_config (scnc->ctx, CS_SET, CS_LOC_PROP, locale, */
+/* CS_UNUSED, NULL)) != CS_SUCCEED) { */
+
+ ret = cs_config (scnc->ctx,
+ CS_SET,
+ CS_LOC_PROP,
+ locale,
+ CS_UNUSED,
+ NULL);
+
+ if ((ret != CS_SUCCEED)||
+ (sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__)))
+ {
+ gda_log_error (_("Could not configure locale to be '%s'"),
+ targ_locale);
+ cs_loc_drop (scnc->ctx, locale);
+ return FALSE;
+ }
+
+/* if ((ret = cs_loc_drop (scnc->ctx, locale)) != CS_SUCCEED) { */
+
+ ret = cs_loc_drop (scnc->ctx, locale);
+
+ if ((ret != CS_SUCCEED)||
+ (sybase_chkerr(NULL,NULL,cnc,NULL,__PRETTY_FUNCTION__)))
+ {
+ gda_log_error (_("Could not drop locale structure"));
+ return FALSE;
+ }
+
+ gda_log_message ("Selected locale '%s'", targ_locale);
+ return TRUE;
}
// drop remaining cs/ctlib structures and exit
void
gda_sybase_cleanup (sybase_Connection * scnc, CS_RETCODE ret,
- const gchar * msg)
+ const gchar * msg)
{
- g_return_if_fail (scnc != NULL);
+ g_return_if_fail (scnc != NULL);
- gda_log_error (_("Fatal error: %s\n"), msg);
+ gda_log_error (_("Fatal error: %s\n"), msg);
- if (scnc->cnc != NULL) {
- ct_con_drop (scnc->cnc);
- scnc->cnc = NULL;
- }
+ if (scnc->cnc != NULL) {
+ ct_con_drop (scnc->cnc);
+ scnc->cnc = NULL;
+ }
- if (scnc->ctx != NULL) {
- ct_exit (scnc->ctx, CS_FORCE_EXIT);
- cs_ctx_drop (scnc->ctx);
- scnc->ctx = NULL;
- }
+ if (scnc->ctx != NULL) {
+ ct_exit (scnc->ctx, CS_FORCE_EXIT);
+ cs_ctx_drop (scnc->ctx);
+ scnc->ctx = NULL;
+ }
}
/*
@@ -1124,83 +1295,85 @@
static gint
gda_sybase_init_dsn_properties (GdaServerConnection * cnc, const gchar * dsn)
{
- sybase_Connection *scnc;
- gchar *ptr_s, *ptr_e;
+ sybase_Connection *scnc;
+ gchar *ptr_s, *ptr_e;
- g_return_val_if_fail (cnc != NULL, -1);
- scnc = (sybase_Connection *)
- gda_server_connection_get_user_data (cnc);
-
- if (scnc) {
- /* parse connection string */
- ptr_s = (gchar *) dsn;
- while (ptr_s && *ptr_s) {
- ptr_e = strchr (ptr_s, ';');
-
- if (ptr_e)
- *ptr_e = '\0';
-
- // HOST implies HOSTNAME ;-)
- if (strncasecmp (ptr_s, "HOST", strlen ("HOST")) == 0)
- scnc->ret =
- ct_con_props (scnc->cnc, CS_SET,
- CS_HOSTNAME,
- (CS_CHAR *)
- get_value (ptr_s),
- CS_NULLTERM, NULL);
- else if (strncasecmp
- (ptr_s, "USERNAME",
- strlen ("USERNAME")) == 0)
- scnc->ret =
- ct_con_props (scnc->cnc, CS_SET,
- CS_USERNAME,
- (CS_CHAR *)
- get_value (ptr_s),
- CS_NULLTERM, NULL);
- else if (strncasecmp
- (ptr_s, "APPNAME", strlen ("APPNAME")) == 0)
- scnc->ret =
- ct_con_props (scnc->cnc, CS_SET,
- CS_APPNAME,
- (CS_CHAR *)
- get_value (ptr_s),
- CS_NULLTERM, NULL);
- else if (strncasecmp
- (ptr_s, "PASSWORD",
- strlen ("PASSWORD")) == 0)
- scnc->ret =
- ct_con_props (scnc->cnc, CS_SET,
- CS_PASSWORD,
- (CS_CHAR *)
- get_value (ptr_s),
- CS_NULLTERM, NULL);
- else if (strncasecmp
- (ptr_s, "DATABASE",
- strlen ("DATABASE")) == 0) {
- scnc->ret = CS_SUCCEED;
- if (scnc->database) {
- g_free ((gpointer) scnc->database);
- }
- scnc->database =
- g_strdup_printf ("%s",
- get_value (ptr_s));
- }
-
- sybase_chkerr (NULL, NULL, cnc, NULL,
- __PRETTY_FUNCTION__);
- if (scnc->ret != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret,
- "Could not proceed dsn settings.\n");
- return -1;
- }
-
- ptr_s = ptr_e;
- if (ptr_s)
- ptr_s++;
- }
- }
-
- return 0;
+ g_return_val_if_fail (cnc != NULL, -1);
+ scnc = (sybase_Connection *)
+ gda_server_connection_get_user_data (cnc);
+
+ if (scnc)
+ {
+ /* parse connection string */
+ ptr_s = (gchar *) dsn;
+ while (ptr_s && *ptr_s)
+ {
+ ptr_e = strchr (ptr_s, ';');
+
+ if (ptr_e)
+ *ptr_e = '\0';
+
+ // HOST implies HOSTNAME ;-)
+ if (strncasecmp (ptr_s, "HOST", strlen ("HOST")) == 0)
+ scnc->ret =
+ ct_con_props (scnc->cnc, CS_SET,
+ CS_HOSTNAME,
+ (CS_CHAR *)
+ get_value (ptr_s),
+ CS_NULLTERM, NULL);
+ else if (strncasecmp
+ (ptr_s, "USERNAME",
+ strlen ("USERNAME")) == 0)
+
+ scnc->ret =
+ ct_con_props (scnc->cnc, CS_SET,
+ CS_USERNAME,
+ (CS_CHAR *)
+ get_value (ptr_s),
+ CS_NULLTERM, NULL);
+ else if (strncasecmp
+ (ptr_s, "APPNAME", strlen ("APPNAME")) == 0)
+ scnc->ret =
+ ct_con_props (scnc->cnc, CS_SET,
+ CS_APPNAME,
+ (CS_CHAR *)
+ get_value (ptr_s),
+ CS_NULLTERM, NULL);
+ else if (strncasecmp
+ (ptr_s, "PASSWORD",
+ strlen ("PASSWORD")) == 0)
+ scnc->ret =
+ ct_con_props (scnc->cnc, CS_SET,
+ CS_PASSWORD,
+ (CS_CHAR *)
+ get_value (ptr_s),
+ CS_NULLTERM, NULL);
+ else if (strncasecmp
+ (ptr_s, "DATABASE",
+ strlen ("DATABASE")) == 0) {
+ scnc->ret = CS_SUCCEED;
+ if (scnc->database) {
+ g_free ((gpointer) scnc->database);
+ }
+ scnc->database =
+ g_strdup_printf ("%s",
+ get_value (ptr_s));
+ }
+
+ sybase_chkerr (NULL, NULL, cnc, NULL,
+ __PRETTY_FUNCTION__);
+ if (scnc->ret != CS_SUCCEED) {
+ gda_sybase_cleanup (scnc, scnc->ret,
+ "Could not proceed dsn settings.\n");
+ return -1;
+ }
+
+ ptr_s = ptr_e;
+ if (ptr_s)
+ ptr_s++;
+ }
+ }
+ return 0;
}
/*
@@ -1210,36 +1383,36 @@
static gchar *
get_value (gchar * ptr)
{
- while (*ptr && (*ptr != '='))
- ptr++;
+ while (*ptr && (*ptr != '='))
+ ptr++;
- if (!*ptr) {
- return NULL;
- }
- ptr++;
- if (!*ptr) {
- return NULL;
- }
- while (*ptr && isspace (*ptr))
+ if (!*ptr) {
+ return NULL;
+ }
ptr++;
+ if (!*ptr) {
+ return NULL;
+ }
+ while (*ptr && isspace (*ptr))
+ ptr++;
- return (g_strdup (ptr));
+ return (g_strdup (ptr));
}
static gchar *
get_option (const gchar * dsn, const gchar * opt_name)
{
- gchar *ptr = NULL;
- gchar *opt = NULL;
+ gchar *ptr = NULL;
+ gchar *opt = NULL;
- if (!(opt = strstr (dsn, opt_name))) {
- return NULL;
- }
- opt += strlen (opt_name);
- ptr = strchr (opt, ';');
+ if (!(opt = strstr (dsn, opt_name))) {
+ return NULL;
+ }
+ opt += strlen (opt_name);
+ ptr = strchr (opt, ';');
- if (ptr)
- *ptr = '\0';
+ if (ptr)
+ *ptr = '\0';
- return (g_strdup (opt));
+ return (g_strdup (opt));
}
Index: gda-sybase-connection.h
===================================================================
RCS file: /cvs/gnome/libgda/providers/gda-sybase-server/Attic/gda-sybase-connection.h,v
retrieving revision 1.5.4.1
diff -u -u -r1.5.4.1 gda-sybase-connection.h
--- gda-sybase-connection.h 2001/09/16 20:12:39 1.5.4.1
+++ gda-sybase-connection.h 2001/11/22 04:42:47
@@ -1,115 +1,123 @@
-/*
- * $Id: gda-sybase-connection.h,v 1.5.4.1 2001/09/16 20:12:39 rodrigo Exp $
- *
- * GNOME DB sybase Provider
- * Copyright (C) 2000 Rodrigo Moya
- * Copyright (C) 2000 Stephan Heinze
- * Copyright (C) 2000 Holger Thon
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#if !defined(__gda_sybase_connection_h__)
-# define __gda_sybase_connection_h__
-
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-
-#include <gda-server.h>
-#include <glib.h>
-#include <ctpublic.h>
-#include "gda-sybase.h"
-
-// The application name we tell sybase we are
-//
-#define GDA_SYBASE_DEFAULT_APPNAME "gda-sybase-srv"
-
-
-/*
- * Per-object specific structures
- */
-
-typedef struct _sybase_Error
-{
- guint err_type;
- CS_CLIENTMSG cslib_msg;
- CS_CLIENTMSG client_msg;
- CS_SERVERMSG server_msg;
- gchar *udeferr_msg;
-}
-sybase_Error;
-
-typedef struct _sybase_Connection
-{
- CS_CONTEXT *ctx;
- CS_CONNECTION *cnc;
- CS_RETCODE ret;
-
- gboolean cs_diag; // wether we can use cs_diag for cslib messages
- gboolean ct_diag; // wether we can use ct_diag for ctlib messages
-
- GdaError *error;
- sybase_Error serr;
-
- gchar *database;
-}
-sybase_Connection;
-
-/*
- * Server implementation prototypes
- */
-gboolean gda_sybase_connection_new (GdaServerConnection * cnc);
-gint gda_sybase_connection_open (GdaServerConnection * cnc, const gchar * dsn,
- const gchar * user, const gchar * passwd);
-void gda_sybase_connection_close (GdaServerConnection * cnc);
-gint gda_sybase_connection_begin_transaction (GdaServerConnection * cnc);
-gint gda_sybase_connection_commit_transaction (GdaServerConnection * cnc);
-gint gda_sybase_connection_rollback_transaction (GdaServerConnection * cnc);
-GdaServerRecordset *gda_sybase_connection_open_schema (GdaServerConnection *
- cnc,
- GdaError * error,
- GDA_Connection_QType t,
- GDA_Connection_Constraint
- * constraints,
- gint length);
-glong gda_sybase_connection_modify_schema (GdaServerConnection * cnc,
- GDA_Connection_QType t,
- GDA_Connection_Constraint *
- constraints, gint length);
-gint gda_sybase_connection_start_logging (GdaServerConnection * cnc,
- const gchar * filename);
-gint gda_sybase_connection_stop_logging (GdaServerConnection * cnc);
-gchar *gda_sybase_connection_create_table (GdaServerConnection * cnc,
- GDA_RowAttributes * columns);
-gboolean gda_sybase_connection_supports (GdaServerConnection *,
- GDA_Connection_Feature feature);
-const GDA_ValueType gda_sybase_connection_get_gda_type (GdaServerConnection *,
- gulong);
-const gshort gda_sybase_connection_get_c_type (GdaServerConnection *,
- GDA_ValueType type);
-gchar *gda_sybase_connection_sql2xml (GdaServerConnection * cnc,
- const gchar * sql);
-gchar *gda_sybase_connection_xml2sql (GdaServerConnection * cnc,
- const gchar * xml);
-void gda_sybase_connection_free (GdaServerConnection * cnc);
-void gda_sybase_connection_clear_user_data (GdaServerConnection *, gboolean);
-
-gboolean gda_sybase_connection_dead (GdaServerConnection *);
-gboolean gda_sybase_connection_reopen (GdaServerConnection *);
-CS_RETCODE gda_sybase_connection_select_database (GdaServerConnection *,
- const gchar * dbname);
-
-#endif
+/*
+ * $Id: gda-sybase-connection.h,v 1.5.4.1 2001/09/16 20:12:39 rodrigo Exp $
+ *
+ * GNOME DB sybase Provider
+ * Copyright (C) 2000 Rodrigo Moya
+ * Copyright (C) 2000 Stephan Heinze
+ * Copyright (C) 2000 Holger Thon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#if !defined(__gda_sybase_connection_h__)
+# define __gda_sybase_connection_h__
+
+#if defined(HAVE_CONFIG_H)
+# include <config.h>
+#endif
+
+#include <gda-server.h>
+#include <glib.h>
+#include <ctpublic.h>
+#include "gda-sybase.h"
+
+// The application name we tell sybase we are
+//
+#define GDA_SYBASE_DEFAULT_APPNAME "gda-sybase-srv"
+
+
+/*
+ * Per-object specific structures
+ */
+
+typedef struct _sybase_Error
+{
+/* guint err_type; */
+
+/* CS_CLIENTMSG cslib_msg; */
+/* CS_CLIENTMSG client_msg; */
+/* CS_SERVERMSG server_msg */;
+/* gchar *udeferr_msg; */
+
+ gchar *eMessage;
+
+}
+sybase_Error;
+
+typedef struct _sybase_Connection
+{
+ CS_CONTEXT *ctx;
+ CS_CONNECTION *cnc;
+ CS_RETCODE ret;
+
+ gboolean cs_diag; // wether we can use cs_diag for cslib messages
+ gboolean ct_diag; // wether we can use ct_diag for ctlib messages
+
+ GdaError *error;
+ sybase_Error serr;
+
+ gchar *database;
+}
+sybase_Connection;
+
+/*
+ * Server implementation prototypes
+ */
+gboolean gda_sybase_connection_new (GdaServerConnection * cnc);
+gint gda_sybase_connection_open (GdaServerConnection * cnc, const gchar * dsn,
+ const gchar * user, const gchar * passwd);
+void gda_sybase_connection_close (GdaServerConnection * cnc);
+gint gda_sybase_connection_begin_transaction (GdaServerConnection * cnc);
+gint gda_sybase_connection_commit_transaction (GdaServerConnection * cnc);
+gint gda_sybase_connection_rollback_transaction (GdaServerConnection * cnc);
+GdaServerRecordset *gda_sybase_connection_open_schema (GdaServerConnection *
+ cnc,
+ GdaError * error,
+ GDA_Connection_QType t,
+ GDA_Connection_Constraint
+ * constraints,
+ gint length);
+glong gda_sybase_connection_modify_schema (GdaServerConnection * cnc,
+ GDA_Connection_QType t,
+ GDA_Connection_Constraint *
+ constraints, gint length);
+gint gda_sybase_connection_start_logging (GdaServerConnection * cnc,
+ const gchar * filename);
+gint gda_sybase_connection_stop_logging (GdaServerConnection * cnc);
+gchar *gda_sybase_connection_create_table (GdaServerConnection * cnc,
+ GDA_RowAttributes * columns);
+gboolean gda_sybase_connection_supports (GdaServerConnection *,
+ GDA_Connection_Feature feature);
+const GDA_ValueType gda_sybase_connection_get_gda_type (GdaServerConnection *,
+ gulong);
+const gshort gda_sybase_connection_get_c_type (GdaServerConnection *,
+ GDA_ValueType type);
+gchar *gda_sybase_connection_sql2xml (GdaServerConnection * cnc,
+ const gchar * sql);
+gchar *gda_sybase_connection_xml2sql (GdaServerConnection * cnc,
+ const gchar * xml);
+void gda_sybase_connection_free (GdaServerConnection * cnc);
+void gda_sybase_connection_clear_user_data (GdaServerConnection *, gboolean);
+
+gboolean gda_sybase_connection_dead (GdaServerConnection *);
+gboolean gda_sybase_connection_reopen (GdaServerConnection *);
+CS_RETCODE gda_sybase_connection_select_database (GdaServerConnection *,
+ const gchar * dbname);
+
+void gda_sybase_cleanup (sybase_Connection *,
+ CS_RETCODE,
+ const gchar *);
+
+#endif
Index: gda-sybase-error.c
===================================================================
RCS file: /cvs/gnome/libgda/providers/gda-sybase-server/Attic/gda-sybase-error.c,v
retrieving revision 1.4.4.1
diff -u -u -r1.4.4.1 gda-sybase-error.c
--- gda-sybase-error.c 2001/09/16 20:12:39 1.4.4.1
+++ gda-sybase-error.c 2001/11/22 04:42:49
@@ -54,610 +54,874 @@
#include "ctype.h"
// callback handlers
-static CS_RETCODE CS_PUBLIC
-gda_sybase_servermsg_callback (CS_CONTEXT *, CS_CONNECTION *, CS_SERVERMSG *);
-static CS_RETCODE CS_PUBLIC
-gda_sybase_clientmsg_callback (CS_CONTEXT *, CS_CONNECTION *, CS_CLIENTMSG *);
-static CS_RETCODE CS_PUBLIC
-gda_sybase_csmsg_callback (CS_CONTEXT *, CS_CLIENTMSG *);
+/* static CS_RETCODE CS_PUBLIC */
+/* gda_sybase_servermsg_callback (CS_CONTEXT *, CS_CONNECTION *, CS_SERVERMSG *); */
+/* static CS_RETCODE CS_PUBLIC */
+/* gda_sybase_clientmsg_callback (CS_CONTEXT *, CS_CONNECTION *, CS_CLIENTMSG *); */
+/* static CS_RETCODE CS_PUBLIC */
+/* gda_sybase_csmsg_callback (CS_CONTEXT *, CS_CLIENTMSG *); */
-GdaServerConnection *gda_sybase_callback_get_connection (const CS_CONTEXT *,
- const CS_CONNECTION
- *);
+/* GdaServerConnection *gda_sybase_callback_get_connection (const CS_CONTEXT *, */
+/* const CS_CONNECTION */
+/* *); */
void
gda_sybase_error_make (GdaError * error,
- GdaServerRecordset * recset,
- GdaServerConnection * cnc, gchar * where)
-{
- sybase_Connection *scnc = NULL;
- gchar *err_msg = NULL;
-
-#ifdef SYBASE_DEBUG
- gda_log_message (_("gda_sybase_error_make(%p,%p,%p,%p)"), error,
- recset, cnc, where);
-#endif
- g_return_if_fail (cnc != NULL);
- scnc = (sybase_Connection *)
- gda_server_connection_get_user_data (cnc);
- g_return_if_fail (scnc != NULL);
-
- switch (scnc->serr.err_type) {
- case SYBASE_ERR_NONE:
- err_msg =
- g_strdup_printf (_
- ("No error flag ist set, though %s "
- "is called. This may be a bug."),
- __PRETTY_FUNCTION__);
- gda_error_set_description (error,
- (err_msg) ? err_msg :
- "Unknown error");
- case SYBASE_ERR_SERVER:
- err_msg = g_sprintf_servermsg ("Server Message:",
- &scnc->serr.server_msg);
- gda_error_set_description (error,
- (err_msg) ? err_msg :
- "Server error");
- break;
- case SYBASE_ERR_CLIENT:
- err_msg = g_sprintf_clientmsg ("Client Message:",
- &scnc->serr.client_msg);
- gda_error_set_description (error,
- (err_msg) ? err_msg :
- "Client error");
- break;
- case SYBASE_ERR_CSLIB:
- err_msg = g_sprintf_clientmsg ("CS-Lib Message:",
- &scnc->serr.cslib_msg);
- gda_error_set_description (error,
- (err_msg) ? err_msg :
- "Cslib error");
- break;
- case SYBASE_ERR_USERDEF:
- gda_error_set_description (error,
- (scnc->serr.
- udeferr_msg) ? scnc->serr.
- udeferr_msg :
- "gda-sybase error");
- if (scnc->serr.udeferr_msg) {
- g_free ((gpointer) scnc->serr.udeferr_msg);
- }
- break;
- default:
- gda_error_set_description (error, "Unknown error");
- break;
- }
-
- gda_log_error (_("error '%s' at %s"),
- gda_error_get_description (error), where);
-
- if (err_msg) {
- g_free ((gpointer) err_msg);
- }
-
- gda_error_set_number (error, 1);
- gda_error_set_source (error, "[gda-sybase]");
-/* gda_error_set_help_file (error, _("Not available")); */
- gda_error_set_help_context (error, _("Not available"));
- gda_error_set_sqlstate (error, _("error"));
- gda_error_set_native (error,
- gda_error_get_description
- (error));
+ GdaServerRecordset * recset,
+ GdaServerConnection * cnc,
+ gchar * where)
+{
+ sybase_Connection *scnc = NULL;
+ gchar *err_msg = NULL;
+
+ /* #ifdef SYBASE_DEBUG */
+ /* gda_log_message (_("gda_sybase_error_make(%p,%p,%p,%p)"), error, */
+ /* recset, cnc, where); */
+ /* #endif */
+
+ g_return_if_fail (cnc != NULL);
+ scnc = (sybase_Connection *)
+ gda_server_connection_get_user_data (cnc);
+ g_return_if_fail (scnc != NULL);
+
+ err_msg = g_strdup_printf(scnc->serr.eMessage);
+
+ gda_error_set_description (error,
+ (g_strdup(err_msg)) ? err_msg :
+ "Unknown error");
+
+ gda_log_error (_("error '%s' at %s"),
+ gda_error_get_description (error), where);
+
+
+ gda_sybase_debug_msg("--------------------------------------------");
+ gda_sybase_debug_msg("in error make");
+ gda_sybase_debug_msg(scnc->serr.eMessage);
+ gda_sybase_debug_msg("--------------------------------------------");
+
+
+ gda_error_set_number (error, 1);
+ gda_error_set_source (error, "[gda-sybase]");
+ gda_error_set_help_context (error, _("Not available"));
+ gda_error_set_sqlstate (error, _("error"));
+ gda_error_set_native (error,
+ gda_error_get_description
+ (error));
+
+ gda_log_error (_("error '%s' at %s"),
+ gda_error_get_description (error), where);
+
+ if (err_msg)
+ {
+ g_free ((gpointer) err_msg);
+ }
+
+ if (scnc->serr.eMessage)
+ {
+ g_free((gpointer)scnc->serr.eMessage);
+ scnc->serr.eMessage = NULL;
+ }
}
gboolean
gda_sybase_messages_install (GdaServerConnection * cnc)
{
- sybase_Connection *scnc = NULL;
- g_return_val_if_fail (cnc != NULL, FALSE);
- scnc = (sybase_Connection *)
- gda_server_connection_get_user_data (cnc);
- g_return_val_if_fail (scnc != NULL, FALSE);
-
- if ((scnc->ctx)
- &&
- ((scnc->ret =
- cs_diag (scnc->ctx, CS_INIT, CS_UNUSED, CS_UNUSED,
- NULL)) == CS_SUCCEED)) {
- scnc->cs_diag = TRUE;
-#ifdef SYBASE_DEBUG
- gda_log_message (_("cs_diag() initialized"));
-#endif
- }
- else {
- gda_log_error (_("Could not initialize cs_diag()"));
- }
-
- if ((scnc->cnc)
- &&
- ((scnc->ret =
- ct_diag (scnc->cnc, CS_INIT, CS_UNUSED, CS_UNUSED,
- NULL)) == CS_SUCCEED)) {
- scnc->ct_diag = TRUE;
+ /* this function set up open client to use inline error */
+ /* handling */
+
+ sybase_Connection *scnc = NULL;
+ CS_RETCODE ret;
+
+ g_return_val_if_fail (cnc != NULL, FALSE);
+ scnc = (sybase_Connection *)
+ gda_server_connection_get_user_data (cnc);
+ g_return_val_if_fail (scnc != NULL, FALSE);
+
+ if (scnc->ctx)
+ {
+ scnc->ret = cs_diag (scnc->ctx,
+ CS_INIT,
+ CS_UNUSED,
+ CS_UNUSED,
+ NULL);
+ if (scnc->ret == CS_SUCCEED)
+ {
+ scnc->cs_diag = TRUE;
+
+
#ifdef SYBASE_DEBUG
- gda_log_message (_("ct_diag() initialized"));
+ gda_log_message (_("cs_diag() initialized"));
#endif
- }
- else {
- gda_log_error (_("Could not initialize ct_diag()"));
- }
-
- // Succeeding means both succeed
- return ((scnc->cs_diag == TRUE)
- && (scnc->ct_diag == TRUE)) ? TRUE : FALSE;
-}
-void
-gda_sybase_messages_uninstall (GdaServerConnection * cnc)
-{
- // Seems the diag info is dropped with the context/connection structure
-}
+ }
-void
-sybase_chkerr (GdaError * error,
- GdaServerRecordset * recset,
- GdaServerConnection * _cnc,
- GdaServerCommand * _cmd, gchar * where)
-{
- GdaServerConnection *cnc = NULL;
- GdaServerCommand *cmd = NULL;
- sybase_Connection *scnc = NULL;
- sybase_Command *scmd = NULL;
- sybase_Recordset *srecset = NULL;
- CS_RETCODE ret = CS_SUCCEED;
- CS_INT messages = 0;
-
- if (_cnc) {
- cnc = _cnc;
- }
- else if (recset) {
- cnc = gda_server_recordset_get_connection (recset);
- srecset = gda_server_recordset_get_user_data (recset);
- }
- else {
- gda_log_error (_("%s could not find server implementation"),
- __PRETTY_FUNCTION__);
- return;
- }
- scnc = (sybase_Connection *)
- gda_server_connection_get_user_data (cnc);
- if (scnc == NULL) {
- gda_log_error (_("%s could not get cnc userdata"),
- __PRETTY_FUNCTION__);
- return;
- }
- if (_cmd) {
- cmd = _cmd;
- }
-
- if ((scnc->ct_diag == TRUE) && (scnc->cnc)) {
- ret = ct_diag (scnc->cnc, CS_STATUS, CS_ALLMSG_TYPE,
- CS_UNUSED, &messages);
- if (ret != CS_SUCCEED) {
- gda_log_error (_("Could not get # of messages"));
- return;
- }
- else if (messages > 0) {
-#ifdef SYBASE_DEBUG
- if (messages > 1) {
- gda_log_message (_
- ("%d ctlib messages to fetch"),
- messages);
- }
- else {
- gda_log_message (_
- ("%d ctlib message to fetch"),
- messages);
- }
-#endif
- gda_sybase_messages_handle_clientmsg (error, recset,
- cnc, where);
- gda_sybase_messages_handle_servermsg (error, recset,
- cnc, where);
- }
- }
- if ((scnc->cs_diag == TRUE) && (scnc->ctx)) {
- gda_sybase_messages_handle_csmsg (error, recset, cnc, where);
- }
-
- // Make sure err_type is set correct again
- scnc->serr.err_type = SYBASE_ERR_NONE;
-}
-
-CS_RETCODE
-sybase_exec_chk (CS_RETCODE * retvar,
- CS_RETCODE retval,
- GdaError * err,
- GdaServerRecordset * rec,
- GdaServerConnection * cnc,
- GdaServerCommand * cmd, gchar * where)
-{
- sybase_chkerr (err, rec, cnc, cmd, where);
+ else
+ {
+ gda_log_error (_("Could not initialize cs_diag()"));
+ }
+ }
+ if (scnc->cnc)
+ {
+ scnc->ret = ct_diag (scnc->cnc,
+ CS_INIT,
+ CS_UNUSED,
+ CS_UNUSED,
+ NULL);
+ if (scnc->ret == CS_SUCCEED)
+ {
- return ((retvar) ? (*retvar = retval) : retval);
-}
+ scnc->ct_diag = TRUE;
-void
-gda_sybase_messages_handle (GdaError * error,
- GdaServerRecordset * recset,
- GdaServerConnection * cnc, gchar * where)
-{
- if (error == NULL) {
- gda_log_error (_
- ("error is nullpointer in gda_sybase_messages_handle"));
- return;
- }
- sybase_chkerr (error, recset, cnc, NULL, where);
-}
-void
-gda_sybase_messages_handle_clientmsg (GdaError * error,
- GdaServerRecordset * recset,
- GdaServerConnection * cnc,
- gchar * where)
-{
- sybase_Connection *scnc = NULL;
- CS_RETCODE ret = CS_SUCCEED;
- CS_INT msgcnt = 0;
- CS_INT msgcur = 0;
-
- g_return_if_fail (cnc != NULL);
- scnc = (sybase_Connection *)
- gda_server_connection_get_user_data (cnc);
- g_return_if_fail (scnc != NULL);
- g_return_if_fail (scnc->ct_diag != FALSE);
-
- ret = ct_diag (scnc->cnc, CS_STATUS, CS_CLIENTMSG_TYPE, CS_UNUSED,
- &msgcnt);
- if (ret != CS_SUCCEED) {
- gda_log_error (_("Could not get # of server messages"));
- return;
- }
- if (msgcnt == 0) {
- return;
- }
#ifdef SYBASE_DEBUG
- if (msgcnt > 1) {
- gda_log_message (_("Fetching %d client messages"), msgcnt);
- }
- else {
- gda_log_message (_("Fetching %d client message"), msgcnt);
- }
+ gda_log_message (_("ct_diag() initialized"));
#endif
- while (msgcur < msgcnt) {
- msgcur++;
-
- ret = ct_diag (scnc->cnc, CS_GET, CS_CLIENTMSG_TYPE, msgcur,
- &scnc->serr.client_msg);
- if (ret != CS_SUCCEED) {
- gda_log_error (_("Could not get client msg # %d"),
- msgcur);
- return;
- }
- scnc->serr.err_type = SYBASE_ERR_CLIENT;
- // if (!error) {
- gda_sybase_log_clientmsg ("Client Message:",
- &scnc->serr.client_msg);
- // } else {
- // gda_server_error_make(error, recset, cnc, where);
- // }
-
- // Check if any new message came in
- if (msgcur == msgcnt) {
- ret = ct_diag (scnc->cnc, CS_STATUS,
- CS_CLIENTMSG_TYPE, CS_UNUSED, &msgcnt);
- if (ret != CS_SUCCEED) {
- gda_log_error (_
- ("Could not get # of client messages"));
- return;
- }
- }
- }
- ret = ct_diag (scnc->cnc, CS_CLEAR, CS_CLIENTMSG_TYPE,
- CS_UNUSED, &scnc->serr.client_msg);
- if (ret != CS_SUCCEED) {
- gda_log_error (_("Could not clear client messages"));
- }
-}
-void
-gda_sybase_messages_handle_servermsg (GdaError * error,
- GdaServerRecordset * recset,
- GdaServerConnection * cnc,
- gchar * where)
-{
- GdaError *serverr = error;
- sybase_Connection *scnc = NULL;
- CS_RETCODE ret = CS_SUCCEED;
- CS_INT msgcur = 0;
- CS_INT msgcnt = 0;
-
- g_return_if_fail (cnc != NULL);
- scnc = (sybase_Connection *)
- gda_server_connection_get_user_data (cnc);
- g_return_if_fail (scnc != NULL);
- g_return_if_fail (scnc->ct_diag != FALSE);
-
- ret = ct_diag (scnc->cnc, CS_STATUS, CS_SERVERMSG_TYPE, CS_UNUSED,
- &msgcnt);
- if (ret != CS_SUCCEED) {
- gda_log_error (_("Could not get # of server messages"));
- return;
- }
- if (msgcnt == 0) {
- return;
- }
-#ifdef SYBASE_DEBUG
- if (msgcnt > 1) {
- gda_log_message (_("Fetching %d server messages"), msgcnt);
- }
- else {
- gda_log_message (_("Fetching %d server message"), msgcnt);
- }
-#endif
- while (msgcur < msgcnt) {
- msgcur++;
+ }
+ }
+ else
+ {
+ gda_log_error (_("Could not initialize ct_diag()"));
+ }
+
+ if ((scnc->ct_diag)&&(scnc->cs_diag))
+ return TRUE;
+ else
+ return FALSE;
+}
+
+/* void */
+/* gda_sybase_messages_uninstall (GdaServerConnection * cnc) */
+/* { */
+// Seems the diag info is dropped with the context/connection structure
+/* } */
- ret = ct_diag (scnc->cnc, CS_GET, CS_SERVERMSG_TYPE, msgcur,
- &scnc->serr.server_msg);
- if (ret != CS_SUCCEED) {
- gda_log_error (_("Could not get server msg # %d"),
- msgcur);
- return;
- }
+gboolean
+sybase_chkerr (GdaError * error,
+ GdaServerRecordset * recset,
+ GdaServerConnection * _cnc,
+ GdaServerCommand * _cmd,
+ gchar * where)
+{
+
+ /* this function will get called after every open client function */
+ /* call to check for error messages. it will return TRUE if there */
+ /* is a server/openclient message that we need to worry about */
+
+ GdaServerConnection *cnc = NULL;
+ GdaServerCommand *cmd = NULL;
+ sybase_Connection *scnc = NULL;
+ sybase_Command *scmd = NULL;
+ sybase_Recordset *srecset = NULL;
+ CS_RETCODE ret = CS_SUCCEED;
+ CS_INT messages = 0;
+ gboolean oneWasBad = FALSE;
+ gboolean msgRet = FALSE;
+ gchar message[2000];
+
+
+ if (_cnc)
+ {
+ cnc = _cnc;
+ }
+ else
+ {
+ gda_log_error (_("%s could not find server implementation"),
+ __PRETTY_FUNCTION__);
+ return TRUE;
+ }
+ scnc = (sybase_Connection *)
+ gda_server_connection_get_user_data (cnc);
+ if (scnc == NULL)
+ {
+ gda_log_error (_("%s could not get cnc userdata"),
+ __PRETTY_FUNCTION__);
+ return TRUE;
+ }
+
+ if (_cmd)
+ {
+ cmd = _cmd;
+ }
+ if ((scnc->ct_diag == TRUE) && (scnc->cnc))
+ {
+ ret = ct_diag (scnc->cnc,
+ CS_STATUS,
+ CS_ALLMSG_TYPE,
+ CS_UNUSED,
+ &messages);
+ if (ret != CS_SUCCEED)
+ {
+ gda_log_error (_("Could not get # of messages"));
+ return TRUE;
+ }
+ else if (messages > 0)
+ {
+ msgRet = gda_sybase_messages_handle_clientmsg (error,
+ recset,
+ cnc,
+ where);
+ if (msgRet)
+ {
+ oneWasBad = TRUE;
+ gda_sybase_debug_msg("handle clientmsg returned a bad thing");
+ }
+
+ msgRet = gda_sybase_messages_handle_servermsg (error,
+ recset,
+ cnc,
+ where);
+ if (msgRet)
+ {
+ oneWasBad = TRUE;
+ gda_sybase_debug_msg("handle servermsg returned a bad thing");
+ }
+ }
+ }
+ if ((scnc->cs_diag == TRUE) && (scnc->ctx))
+ {
+ msgRet = gda_sybase_messages_handle_csmsg (error,
+ recset,
+ cnc,
+ where);
+ if (msgRet)
+ {
+ oneWasBad = TRUE;
+ gda_sybase_debug_msg("handle cmsg returned a bad thing");
+ }
+ }
+
+ // Make sure err_type is set correct again
+ /* scnc->serr.err_type = SYBASE_ERR_NONE; */
+
+ if (oneWasBad)
+ {
+ g_snprintf(message,200,"%s - something bad happened above me!?!",where);
+ gda_sybase_debug_msg(message);
+ return TRUE;
+ }
+ else
+ {
+ g_snprintf(message,200,"%s - aok!",where);
+ gda_sybase_debug_msg(message);
+ return FALSE;
+ }
+}
- scnc->serr.err_type = SYBASE_ERR_SERVER;
- // if (!error) {
- gda_sybase_log_servermsg ("Server Message:",
- &scnc->serr.server_msg);
- // } else {
- // if (!serverr) {
- // serverr = gda_server_error_new();
- // }
- // if (serverr) {
- // gda_server_error_make(serverr, recset, cnc, where);
- // }
+gboolean
+gda_sybase_messages_handle_clientmsg (GdaError * error,
+ GdaServerRecordset * recset,
+ GdaServerConnection * cnc,
+ gchar * where)
+{
+
+ /* this function will return TRUE if the client message is one we should */
+ /*worry about. */
+
+ sybase_Connection *scnc = NULL;
+ CS_RETCODE ret = CS_SUCCEED;
+ CS_INT msgcnt = 0;
+ CS_INT msgcur = 0;
+ GdaError *err;
+ gchar *message;
+ gboolean error_occured = FALSE;
+ CS_CLIENTMSG msg;
+
+
+ g_return_if_fail (cnc != NULL);
+ scnc = (sybase_Connection *)
+ gda_server_connection_get_user_data (cnc);
+ g_return_if_fail (scnc != NULL);
+ g_return_if_fail (scnc->ct_diag != FALSE);
+
+ ret = ct_diag (scnc->cnc,
+ CS_STATUS,
+ CS_CLIENTMSG_TYPE,
+ CS_UNUSED,
+ &msgcnt);
+
+ if (ret != CS_SUCCEED)
+ {
+ message = g_new0(gchar,200);
+ g_snprintf(message,200,"%s",
+ _("ct_diag failed, Could not get # of client messages(1)"));
+ gda_log_error (message);
+ scnc->serr.eMessage=g_strdup(message);
+ err = gda_error_new();
+ gda_server_error_make(err, recset, cnc, __PRETTY_FUNCTION__);
+ g_free((gpointer) message);
+ return TRUE;
+ }
+ if (msgcnt == 0)
+ {
+ return FALSE;
+ }
+ while (msgcur < msgcnt)
+ {
+ msgcur++;
+
+ ret = ct_diag (scnc->cnc,
+ CS_GET,
+ CS_CLIENTMSG_TYPE,
+ msgcur,
+ &msg);
+ if (ret != CS_SUCCEED)
+ {
+ message = g_new0(gchar,200);
+ g_snprintf(message,200,"%s%d",
+ _("Could not get client msg #"),msgcur);
+ gda_log_error (message);
+ err = gda_error_new();
+ scnc->serr.eMessage=g_strdup(message);
+ gda_server_error_make(err,recset,cnc,__PRETTY_FUNCTION__);
+ g_free((gpointer) message);
+ return TRUE;
+ }
+
+ /* only do something if the error is not informational does */
+ /* gnome-db have a way of showing just informational messages? */
+ if (msg.severity != CS_SV_INFORM)
+ {
+ gda_sybase_log_clientmsg (_("Client Message:"),
+ &msg);
+ message = g_sprintf_clientmsg (_("Client Message:"),
+ &msg);
+ scnc->serr.eMessage=g_strdup(message);
+ err = gda_error_new();
+ gda_server_error_make(err, recset, cnc, __PRETTY_FUNCTION__);
+ g_free((gpointer)message);
+ error_occured = TRUE;
+
+ }
+ /* for now, just dump it to the log */
+ else
+ {
+ message = g_sprintf_clientmsg("!!!Client Message INFORMATIONAL!!!:",
+ &msg);
+ g_free((gpointer)message);
+ }
+
+ if (msgcur == msgcnt)
+ {
+ ret = ct_diag (scnc->cnc,
+ CS_STATUS,
+ CS_CLIENTMSG_TYPE,
+ CS_UNUSED,
+ &msgcnt);
+ if (ret != CS_SUCCEED)
+ {
+ message = g_new0(gchar,200);
+ g_snprintf(message,200,"%s",
+ _("ct_diag failed, Could not get # of client messages(2)"));
+ gda_log_error (message);
+ scnc->serr.eMessage=g_strdup(message);
+ gda_server_error_make(err, recset, cnc, __PRETTY_FUNCTION__);
+ g_free((gpointer) message);
+ return TRUE;
+ }
+ }
+ }
+ ret = ct_diag (scnc->cnc,
+ CS_CLEAR,
+ CS_CLIENTMSG_TYPE,
+ CS_UNUSED,
+ &msg);
+ if (ret != CS_SUCCEED)
+ {
+ message = g_new0(gchar,200);
+ g_snprintf(message,200,"%s",
+ _("Could not clear client messages"));
+ gda_log_error (message);
+ scnc->serr.eMessage=g_strdup(message);
+ gda_server_error_make(err, recset, cnc, __PRETTY_FUNCTION__);
+ g_free((gpointer) message);
+ return TRUE;
+ }
+ return (error_occured);
+}
- // Check if current message has any extra error data
- if (scnc->serr.server_msg.status & CS_HASEED) {
- }
- // Check if any new message came in
- if (msgcur == msgcnt) {
- ret = ct_diag (scnc->cnc, CS_STATUS,
- CS_SERVERMSG_TYPE, CS_UNUSED, &msgcnt);
- if (ret != CS_SUCCEED) {
- gda_log_error (_
- ("Could not get # of server messages"));
- return;
- }
- }
- }
- ret = ct_diag (scnc->cnc, CS_CLEAR, CS_SERVERMSG_TYPE,
- CS_UNUSED, &scnc->serr.server_msg);
- if (ret != CS_SUCCEED) {
- gda_log_error (_("Could not clear server messages"));
- }
+gboolean
+gda_sybase_messages_handle_servermsg (GdaError * error,
+ GdaServerRecordset * recset,
+ GdaServerConnection * cnc,
+ gchar * where)
+{
+ GdaError *serverr = error;
+ sybase_Connection *scnc = NULL;
+ CS_RETCODE ret = CS_SUCCEED;
+ CS_INT msgcur = 0;
+ CS_INT msgcnt = 0;
+ gchar *message;
+ GdaError *err;
+ gboolean error_occured = FALSE;
+ CS_SERVERMSG msg;
+ gchar junk[1000];
+
+
+ g_return_if_fail (cnc != NULL);
+ scnc = (sybase_Connection *)
+ gda_server_connection_get_user_data (cnc);
+ g_return_if_fail (scnc != NULL);
+ g_return_if_fail (scnc->ct_diag != FALSE);
+
+ ret = ct_diag (scnc->cnc,
+ CS_STATUS,
+ CS_SERVERMSG_TYPE,
+ CS_UNUSED,
+ &msgcnt);
+ if (ret != CS_SUCCEED)
+ {
+ message = g_new0(gchar,200);
+ g_snprintf(message,200,"%s",
+ _("Could not get # of server messages(1)"));
+ gda_log_error (message);
+ scnc->serr.eMessage=g_strdup(message);
+ err = gda_error_new();
+ gda_server_error_make(err, recset, cnc, __PRETTY_FUNCTION__);
+ g_free((gpointer) message);
+ return TRUE;
+ }
+ if (msgcnt == 0)
+ {
+ return FALSE;
+ }
+ while (msgcur < msgcnt)
+ {
+ msgcur++;
+ ret = ct_diag (scnc->cnc,
+ CS_GET,
+ CS_SERVERMSG_TYPE,
+ msgcur,
+ &msg);
+ if (ret != CS_SUCCEED)
+ {
+ message = g_new0(gchar,200);
+ g_snprintf(message,200,"%s%d",
+ _("Could not get server msg #"),msgcur);
+ gda_log_error (message);
+ scnc->serr.eMessage=g_strdup(message);
+ err = gda_error_new();
+ gda_server_error_make(err, recset, cnc, __PRETTY_FUNCTION__);
+ g_free((gpointer) message);
+ return TRUE;
+ }
+
+ /* for now, just dump informational messages to the log */
+ /* severity of 10 is informational, I think */
+
+
+/* g_snprintf(junk,200,"severity = %d %ld",msg.severity,msg.severity); */
+/* gda_sybase_debug_msg(junk); */
+
+
+ if ((msg.severity == CS_SV_INFORM) || (msg.severity == 10))
+ {
+ message = g_sprintf_servermsg("!!!Server Message INFORMATIONAL!!!:",
+ &msg);
+ g_free((gpointer)message);
+ }
+ /* show an error if it is not informational */
+ else
+ {
+
+ gda_sybase_log_servermsg ("Server Message:",
+ &msg);
+
+ message = g_sprintf_servermsg("Server Message:",
+ &msg);
+ scnc->serr.eMessage = g_strdup(message);
+ err = gda_error_new();
+ gda_server_error_make(err,
+ recset,
+ cnc,
+ __PRETTY_FUNCTION__);
+ g_free((gpointer)message);
+ error_occured = TRUE;
+ }
+
+
+ /* Check if current message has any extra error data */
+ if (msg.status == CS_HASEED)
+ {
+ }
+
+ /* Check if any new messages have come in */
+ if (msgcur == msgcnt)
+ {
+ ret = ct_diag (scnc->cnc,
+ CS_STATUS,
+ CS_SERVERMSG_TYPE,
+ CS_UNUSED,
+ &msgcnt);
+ if (ret != CS_SUCCEED)
+ {
+ message = g_new0(gchar,200);
+ g_snprintf(message,200,"%s",
+ _("Could not get # of server messages"));
+ gda_log_error (message);
+ scnc->serr.eMessage=g_strdup(message);
+ err = gda_error_new();
+ gda_server_error_make(err,
+ recset,
+ cnc,
+ __PRETTY_FUNCTION__);
+ g_free((gpointer) message);
+ return TRUE;
+ }
+ }
+ }
+ ret = ct_diag (scnc->cnc,
+ CS_CLEAR,
+ CS_SERVERMSG_TYPE,
+ CS_UNUSED,
+ &msg);
+ if (ret != CS_SUCCEED)
+ {
+ message = g_new0(gchar,200);
+ g_snprintf(message,200,"%s",
+ _("Could not clear server messages"));
+ gda_log_error (message);
+ scnc->serr.eMessage=g_strdup(message);
+ err = gda_error_new();
+ gda_server_error_make(err, recset, cnc, __PRETTY_FUNCTION__);
+ g_free((gpointer) message);
+ return TRUE;
+ }
+ return(error_occured);
}
-void
+gboolean
gda_sybase_messages_handle_csmsg (GdaError * error,
- GdaServerRecordset * recset,
- GdaServerConnection * cnc, gchar * where)
-{
- sybase_Connection *scnc = NULL;
- CS_RETCODE ret = CS_SUCCEED;
- CS_INT msgcnt = 0;
- CS_INT msgcur = 0;
-
- g_return_if_fail (cnc != NULL);
- scnc = (sybase_Connection *)
- gda_server_connection_get_user_data (cnc);
- g_return_if_fail (scnc != NULL);
- ret = cs_diag (scnc->ctx, CS_STATUS, CS_CLIENTMSG_TYPE, CS_UNUSED,
- &msgcnt);
-
- if (ret != CS_SUCCEED) {
- gda_log_error (_("Could not get # of cslib messages"));
- return;
- }
- if (msgcnt == 0) {
- return;
- }
+ GdaServerRecordset * recset,
+ GdaServerConnection * cnc,
+ gchar * where)
+{
+ sybase_Connection *scnc = NULL;
+ CS_RETCODE ret = CS_SUCCEED;
+ CS_INT msgcnt = 0;
+ CS_INT msgcur = 0;
+ gchar *message;
+ GdaError *err;
+ gboolean error_occured = FALSE;
+ CS_CLIENTMSG msg;
+
+ g_return_if_fail (cnc != NULL);
+ scnc = (sybase_Connection *)
+ gda_server_connection_get_user_data (cnc);
+ g_return_if_fail (scnc != NULL);
+
+ ret = cs_diag (scnc->ctx,
+ CS_STATUS,
+ CS_CLIENTMSG_TYPE,
+ CS_UNUSED,
+ &msgcnt);
+
+ if (ret != CS_SUCCEED)
+ {
+
+ message = g_new0(gchar,200);
+ g_snprintf(message,200,"%s",
+ _("Could not get # of cslib messages"));
+ gda_log_error (message);
+ scnc->serr.eMessage=g_strdup(message);
+ err = gda_error_new();
+ gda_server_error_make(err, recset, cnc, __PRETTY_FUNCTION__);
+ g_free((gpointer) message);
+ return (TRUE);
+ }
+ if (msgcnt == 0)
+ {
+ return (FALSE);
+ }
+
+
#ifdef SYBASE_DEBUG
- if (msgcnt > 1) {
- gda_log_message (_("Fetching %d cslib messages"), msgcnt);
- }
- else {
- gda_log_message (_("Fetching %d cslib message"), msgcnt);
- }
+ if (msgcnt > 1) {
+ gda_log_message (_("Fetching %d cslib messages"), msgcnt);
+ }
+ else {
+ gda_log_message (_("Fetching %d cslib message"), msgcnt);
+ }
#endif
- while (msgcur < msgcnt) {
- msgcur++;
- ret = cs_diag (scnc->ctx, CS_GET, CS_CLIENTMSG_TYPE, msgcur,
- &scnc->serr.cslib_msg);
- if (ret != CS_SUCCEED) {
- gda_log_error (_("Could not get cslib msg # %d"),
- msgcur);
- return;
- }
- scnc->serr.err_type = SYBASE_ERR_CSLIB;
- // if (!error) {
- gda_sybase_log_clientmsg ("CS-Library message:",
- &scnc->serr.cslib_msg);
- // } else {
- // gda_server_error_make(error, recset, cnc, where);
- // }
-
- // Check if any new message came in
- if (msgcur == msgcnt) {
- ret = cs_diag (scnc->ctx, CS_STATUS,
- CS_CLIENTMSG_TYPE, CS_UNUSED, &msgcnt);
- if (ret != CS_SUCCEED) {
- gda_log_error (_
- ("Could not get # of cslib messages"));
- return;
- }
- }
- }
- ret = cs_diag (scnc->ctx, CS_CLEAR, CS_CLIENTMSG_TYPE,
- CS_UNUSED, &scnc->serr.cslib_msg);
- if (ret != CS_SUCCEED) {
- gda_log_error (_("Could not clear cslib messages"));
- }
+ while (msgcur < msgcnt)
+ {
+ msgcur++;
+ ret = cs_diag (scnc->ctx,
+ CS_GET,
+ CS_CLIENTMSG_TYPE,
+ msgcur,
+ &msg);
+
+ if (ret != CS_SUCCEED)
+ {
+ message = g_new0(gchar,200);
+ g_snprintf(message,200,"%s%d",
+ _("Could not get cslib msg #"),msgcur);
+ gda_log_error (message);
+ scnc->serr.eMessage=g_strdup(message);
+ err = gda_error_new();
+ gda_server_error_make(err, recset, cnc, __PRETTY_FUNCTION__);
+ g_free((gpointer) message);
+ return (TRUE);
+ }
+
+ gda_sybase_log_clientmsg ("CS-Library message:",
+ &msg);
+
+ /* only do something if the error is not informational does */
+ /* gnome-db have a way of showing just informational messages? */
+ if (msg.severity != CS_SV_INFORM)
+ {
+ gda_sybase_log_clientmsg (_("Client Message:"),
+ &msg);
+ message = g_sprintf_clientmsg (_("Client Message:"),
+ &msg);
+ scnc->serr.eMessage=g_strdup(message);
+ err = gda_error_new();
+ gda_server_error_make(err, recset, cnc, __PRETTY_FUNCTION__);
+ g_free((gpointer)message);
+ error_occured = TRUE;
+ }
+
+ /* Check if any new messages have come in */
+ if (msgcur == msgcnt)
+ {
+ ret = cs_diag (scnc->ctx,
+ CS_STATUS,
+ CS_CLIENTMSG_TYPE,
+ CS_UNUSED,
+ &msgcnt);
+ if (ret != CS_SUCCEED)
+ {
+ message = g_new0(gchar,200);
+ g_snprintf(message,200,"%s",
+ _("Could not get # of cslib messages(2)"));
+ gda_log_error (message);
+ scnc->serr.eMessage=g_strdup(message);
+ err = gda_error_new();
+ gda_server_error_make(err, recset, cnc, __PRETTY_FUNCTION__);
+ g_free((gpointer) message);
+ return TRUE;
+ }
+ }
+ }
+ ret = cs_diag (scnc->ctx,
+ CS_CLEAR,
+ CS_CLIENTMSG_TYPE,
+ CS_UNUSED, &msg);
+ if (ret != CS_SUCCEED)
+ {
+ message = g_new0(gchar,200);
+ g_snprintf(message,200,"%s",
+ _("Could not clear cslib messages"));
+ gda_log_error (message);
+ scnc->serr.eMessage=g_strdup(message);
+ err = gda_error_new();
+ gda_server_error_make(err, recset, cnc, __PRETTY_FUNCTION__);
+ g_free((gpointer) message);
+ return TRUE;
+ }
+ return (error_occured);
}
gchar *
g_sprintf_clientmsg (const gchar * head, CS_CLIENTMSG * msg)
{
- GString *txt = NULL;
+ GString *txt = NULL;
+ gchar *junk;
- g_return_val_if_fail (msg != NULL, NULL);
- txt = g_string_new ("");
- g_return_val_if_fail (txt != NULL, NULL);
-
- g_string_sprintfa (txt,
- "SYB: %s\n\tseverity(%ld) number(%ld) origin(%ld) "
- "layer(%ld)\n\t%s", head,
- (long) CS_SEVERITY (msg->severity),
- (long) CS_NUMBER (msg->msgnumber),
- (long) CS_ORIGIN (msg->msgnumber),
- (long) CS_LAYER (msg->msgnumber), msg->msgstring);
+ g_return_val_if_fail (msg != NULL, NULL);
+ txt = g_string_new ("");
+ g_return_val_if_fail (txt != NULL, NULL);
+
+/* g_string_sprintfa (txt, */
+/* _("SYB: %s\n\tseverity(%ld) number(%ld) origin(%ld) "), */
+/* _("layer(%ld)\n\t%s"), head, */
+/* (long) CS_SEVERITY (msg->severity), */
+/* (long) CS_NUMBER (msg->msgnumber), */
+/* (long) CS_ORIGIN (msg->msgnumber), */
+/* (long) CS_LAYER (msg->msgnumber), msg->msgstring); */
- if (msg->osstringlen > 0) {
+
g_string_sprintfa (txt,
- "\n\tOperating system error number(%ld):\n\t%s",
- (long) msg->osnumber, msg->osstring);
- }
+ "%s %s %s(%ld) %s(%ld) %s(%ld) %s(%ld) %s ",
+ _("SYB"),
+ head,
+ _("severity"),
+ (long) CS_SEVERITY (msg->severity),
+ _("number"),
+ (long) CS_NUMBER (msg->msgnumber),
+ _("origin"),
+ (long) CS_ORIGIN (msg->msgnumber),
+ _("layer"),
+ (long) CS_LAYER (msg->msgnumber),
+ msg->msgstring);
+
+ if (msg->osstringlen > 0)
+ {
+ g_string_sprintfa (txt,
+ _("\n\tOperating system error number(%ld):\n\t%s"),
+ (long) msg->osnumber, msg->osstring);
+ }
+ junk = g_strdup(txt->str);
+
+/* gda_sybase_debug_msg(junk); */
- return g_strdup (txt->str);
+ g_string_free(txt,TRUE);
+ return (junk);
}
gchar *
g_sprintf_servermsg (const gchar * head, CS_SERVERMSG * msg)
{
- GString *txt = NULL;
+ GString *txt = NULL;
+ gchar *junk;
- g_return_val_if_fail (msg != NULL, NULL);
- txt = g_string_new ("");
- g_return_val_if_fail (txt != NULL, NULL);
-
- g_string_sprintfa (txt,
- "SYB: %s\n\tnumber(%ld) severity(%ld) state(%ld) "
- "line(%ld)", head, (long) msg->msgnumber,
- (long) msg->severity, (long) msg->state,
- (long) msg->line);
- if (msg->svrnlen > 0)
- g_string_sprintfa (txt, "\n\tServer name: %s", msg->svrname);
- if (msg->proclen > 0)
- g_string_sprintfa (txt, "\n\tProcedure name: %s", msg->proc);
+ g_return_val_if_fail (msg != NULL, NULL);
+ txt = g_string_new ("");
+ g_return_val_if_fail (txt != NULL, NULL);
- g_string_sprintfa (txt, "\n\t%s", msg->text);
-
- return (g_strdup (txt->str));
+ g_string_sprintfa (txt,
+ "SYB SWERVER MSG:%s\n\tnumber(%ld) severity(%ld) state(%ld) line(%ld)",
+ head,
+ (long) msg->msgnumber,
+ (long) msg->severity,
+ (long) msg->state,
+ (long) msg->line);
+
+ if (msg->svrnlen > 0)
+ g_string_sprintfa (txt, "\n\tServer name: %s", msg->svrname);
+ if (msg->proclen > 0)
+ g_string_sprintfa (txt, "\n\tProcedure name: %s", msg->proc);
+
+ g_string_sprintfa (txt, "\n\t%s", msg->text);
+ junk = g_strdup(txt->str);
+
+/* gda_sybase_debug_msg(junk); */
+
+ g_string_free(txt,TRUE);
+
+
+
+ return (junk);
}
-/*
- * Private functions
- *
- *
- */
-
-gint
-gda_sybase_install_error_handlers (GdaServerConnection * cnc)
-{
- sybase_Connection *scnc = NULL;
-
- g_return_val_if_fail (cnc != NULL, -1);
- scnc = (sybase_Connection *)
- gda_server_connection_get_user_data (cnc);
-
- if ((scnc->ret = cs_config (scnc->ctx, CS_SET, CS_MESSAGE_CB,
- (CS_VOID *) gda_sybase_csmsg_callback,
- CS_UNUSED, NULL)) != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret,
- "Could not install cslib callback\n");
- return -1;
- }
- if ((scnc->ret =
- ct_callback (scnc->ctx, NULL, CS_SET, CS_CLIENTMSG_CB,
- (CS_VOID *) gda_sybase_clientmsg_callback))
- != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret, "Could not install ct "
- "callback for client messages\n");
- return -1;
- }
- if ((scnc->ret =
- ct_callback (scnc->ctx, NULL, CS_SET, CS_SERVERMSG_CB,
- (CS_VOID *) gda_sybase_servermsg_callback))
- != CS_SUCCEED) {
- gda_sybase_cleanup (scnc, scnc->ret, "Could not install ct "
- "callback for server messages\n");
- return -1;
- }
-
- return 0;
-}
void
gda_sybase_log_clientmsg (const gchar * head, CS_CLIENTMSG * msg)
{
- gchar *txt = g_sprintf_clientmsg (head, msg);
- g_return_if_fail (txt != NULL);
- gda_log_message (txt);
- g_free ((gpointer) txt);
+ gchar *txt = g_sprintf_clientmsg (head, msg);
+ g_return_if_fail (txt != NULL);
+ gda_log_message (txt);
+ g_free ((gpointer) txt);
}
void
gda_sybase_log_servermsg (const gchar * head, CS_SERVERMSG * msg)
{
- gchar *txt = g_sprintf_servermsg (head, msg);
- g_return_if_fail (txt != NULL);
- gda_log_message (txt);
- g_free ((gpointer) txt);
+ gchar *txt = g_sprintf_servermsg (head, msg);
+ g_return_if_fail (txt != NULL);
+ gda_log_message (txt);
+ g_free ((gpointer) txt);
}
-/*
- * Sybase callback handlers
- * These do nothing so far
- */
-
-GdaServerConnection *
-gda_sybase_callback_get_connection (const CS_CONTEXT * ctx,
- const CS_CONNECTION * cnc)
+void
+gda_sybase_debug_msg(gchar *msg)
{
- // GList *server_list = gda_server_list();
+ /* this will be a stub when I don't need it */
+/* FILE *debug; */
+/* debug = fopen("/home/projects/gda_sybase_debug.log","a+"); */
+/* fprintf(debug,"%s\n",msg); */
+/* fflush(debug); */
+/* fclose(debug); */
+}
- // g_return_val_if_fail(server_list != NULL, NULL);
- return NULL;
-}
-static CS_RETCODE CS_PUBLIC
-gda_sybase_servermsg_callback (CS_CONTEXT * ctx,
- CS_CONNECTION * cnc, CS_SERVERMSG * msg)
-{
- gda_sybase_log_servermsg (_("Server message:"), msg);
- return (CS_SUCCEED);
-}
+/*
+ * Private functions
+ *
+ *
+ */
+
+/* gint */
+/* gda_sybase_install_error_handlers (GdaServerConnection * cnc) */
+/* { */
+/* sybase_Connection *scnc = NULL; */
+
+/* g_return_val_if_fail (cnc != NULL, -1); */
+/* scnc = (sybase_Connection *) */
+/* gda_server_connection_get_user_data (cnc); */
+
+/* if ((scnc->ret = cs_config (scnc->ctx, CS_SET, CS_MESSAGE_CB, */
+/* (CS_VOID *) gda_sybase_csmsg_callback, */
+/* CS_UNUSED, NULL)) != CS_SUCCEED) { */
+/* gda_sybase_cleanup (scnc, scnc->ret, */
+/* "Could not install cslib callback\n"); */
+/* return -1; */
+/* } */
+/* if ((scnc->ret = */
+/* ct_callback (scnc->ctx, NULL, CS_SET, CS_CLIENTMSG_CB, */
+/* (CS_VOID *) gda_sybase_clientmsg_callback)) */
+/* != CS_SUCCEED) { */
+/* gda_sybase_cleanup (scnc, scnc->ret, "Could not install ct " */
+/* "callback for client messages\n"); */
+/* return -1; */
+/* } */
+/* if ((scnc->ret = */
+/* ct_callback (scnc->ctx, NULL, CS_SET, CS_SERVERMSG_CB, */
+/* (CS_VOID *) gda_sybase_servermsg_callback)) */
+/* != CS_SUCCEED) { */
+/* gda_sybase_cleanup (scnc, scnc->ret, "Could not install ct " */
+/* "callback for server messages\n"); */
+/* return -1; */
+/* } */
-static CS_RETCODE CS_PUBLIC
-gda_sybase_clientmsg_callback (CS_CONTEXT * ctx,
- CS_CONNECTION * cnc, CS_CLIENTMSG * msg)
-{
- gda_sybase_log_clientmsg (_("Client message:"), msg);
- return (CS_SUCCEED);
-}
+/* return 0; */
+/* } */
-static CS_RETCODE CS_PUBLIC
-gda_sybase_csmsg_callback (CS_CONTEXT * ctx, CS_CLIENTMSG * msg)
-{
- gda_sybase_log_clientmsg (_("CS-Library error:"), msg);
- return (CS_SUCCEED);
-}
+/*
+ * Sybase callback handlers
+ * These do nothing so far
+ */
+
+/* GdaServerConnection * */
+/* gda_sybase_callback_get_connection (const CS_CONTEXT * ctx, */
+/* const CS_CONNECTION * cnc) */
+/* { */
+// GList *server_list = gda_server_list();
+
+// g_return_val_if_fail(server_list != NULL, NULL);
+
+/* return NULL; */
+/* } */
+
+/* static CS_RETCODE CS_PUBLIC */
+/* gda_sybase_servermsg_callback (CS_CONTEXT * ctx, */
+/* CS_CONNECTION * cnc, CS_SERVERMSG * msg) */
+/* { */
+/* gda_sybase_log_servermsg (_("Server message:"), msg); */
+/* return (CS_SUCCEED); */
+/* } */
+
+/* static CS_RETCODE CS_PUBLIC */
+/* gda_sybase_clientmsg_callback (CS_CONTEXT * ctx, */
+/* CS_CONNECTION * cnc, CS_CLIENTMSG * msg) */
+/* { */
+/* gda_sybase_log_clientmsg (_("Client message:"), msg); */
+/* return (CS_SUCCEED); */
+/* } */
+
+/* static CS_RETCODE CS_PUBLIC */
+/* gda_sybase_csmsg_callback (CS_CONTEXT * ctx, CS_CLIENTMSG * msg) */
+/* { */
+/* gda_sybase_log_clientmsg (_("CS-Library error:"), msg); */
+/* return (CS_SUCCEED); */
+/* } */
Index: gda-sybase-error.h
===================================================================
RCS file: /cvs/gnome/libgda/providers/gda-sybase-server/Attic/gda-sybase-error.h,v
retrieving revision 1.3.4.1
diff -u -u -r1.3.4.1 gda-sybase-error.h
--- gda-sybase-error.h 2001/09/16 20:12:39 1.3.4.1
+++ gda-sybase-error.h 2001/11/22 04:42:50
@@ -1,98 +1,111 @@
-/*
- * $Id: gda-sybase-error.h,v 1.3.4.1 2001/09/16 20:12:39 rodrigo Exp $
- *
- * GNOME DB sybase Provider
- * Copyright (C) 2000 Rodrigo Moya
- * Copyright (C) 2000 Stephan Heinze
- * Copyright (C) 2000 Holger Thon
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#if !defined(__gda_sybase_error_h__)
-# define __gda_sybase_error_h__
-
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-
-#include "gda-sybase.h"
-
-#define GDA_SYBASE_DEBUG_LEVEL 1
-
-#define SYBASE_ERR_NONE 0
-#define SYBASE_ERR_CSLIB 1
-#define SYBASE_ERR_CLIENT 2
-#define SYBASE_ERR_SERVER 3
-#define SYBASE_ERR_USERDEF 4
-#define SYBASE_ERR_UNDEFINED 5
-
-gint gda_sybase_install_error_handlers (GdaServerConnection *);
-
-void gda_sybase_error_make (GdaError * error,
- GdaServerRecordset * recset,
- GdaServerConnection * cnc, gchar * where);
-
-void gda_sybase_cleanup (sybase_Connection *, CS_RETCODE, const gchar *);
-
-gboolean gda_sybase_messages_install (GdaServerConnection *);
-void gda_sybase_messages_uninstall (GdaServerConnection *);
-
-void sybase_chkerr (GdaError *,
- GdaServerRecordset *,
- GdaServerConnection *, GdaServerCommand *, gchar *);
-CS_RETCODE sybase_exec_chk (CS_RETCODE *,
- CS_RETCODE,
- GdaError *,
- GdaServerRecordset *,
- GdaServerConnection *,
- GdaServerCommand *, gchar *);
-
-#ifdef SYBASE_DEBUG
-#define SYB_CHK(retptr, retcode, err, rec, cnc, cmd) \
- sybase_exec_chk(retptr, retcode, err, rec, cnc, cmd, \
- g_strdup_printf("%s at line %d (%s): ", __FILE__, __LINE__, \
- __PRETTY_FUNCTION__))
-#else
-#define SYB_CHK(retptr, retcode, err, rec, cnc, cmd) \
- sybase_exec_chk(retptr, retcode, err, rec, cnc, cmd, \
- __PRETTY_FUNCTION__)
-#endif
-
-void gda_sybase_messages_handle (GdaError *,
- GdaServerRecordset *,
- GdaServerConnection *, gchar * where);
-void gda_sybase_messages_handle_clientmsg (GdaError *,
- GdaServerRecordset *,
- GdaServerConnection *,
- gchar * where);
-void gda_sybase_messages_handle_servermsg (GdaError *,
- GdaServerRecordset *,
- GdaServerConnection *,
- gchar * where);
-void gda_sybase_messages_handle_csmsg (GdaError *,
- GdaServerRecordset *,
- GdaServerConnection *, gchar * where);
-
-// Don't forget to FREE the results :-)
-gchar *g_sprintf_clientmsg (const gchar *, CS_CLIENTMSG *);
-gchar *g_sprintf_servermsg (const gchar *, CS_SERVERMSG *);
-
-void gda_sybase_log_clientmsg (const gchar *, CS_CLIENTMSG *);
-void gda_sybase_log_servermsg (const gchar *, CS_SERVERMSG *);
-
-void gda_sybase_debug_msg (gint, const gchar *);
-
-#endif
+/*
+ * $Id: gda-sybase-error.h,v 1.3.4.1 2001/09/16 20:12:39 rodrigo Exp $
+ *
+ * GNOME DB sybase Provider
+ * Copyright (C) 2000 Rodrigo Moya
+ * Copyright (C) 2000 Stephan Heinze
+ * Copyright (C) 2000 Holger Thon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#if !defined(__gda_sybase_error_h__)
+# define __gda_sybase_error_h__
+
+#if defined(HAVE_CONFIG_H)
+# include <config.h>
+#endif
+
+#include "gda-sybase.h"
+
+#define GDA_SYBASE_DEBUG_LEVEL 1
+
+#define SYBASE_ERR_NONE 0
+#define SYBASE_ERR_CSLIB 1
+#define SYBASE_ERR_CLIENT 2
+#define SYBASE_ERR_SERVER 3
+#define SYBASE_ERR_USERDEF 4
+#define SYBASE_ERR_UNDEFINED 5
+
+gint gda_sybase_install_error_handlers (GdaServerConnection *);
+
+void gda_sybase_error_make (GdaError * error,
+ GdaServerRecordset * recset,
+ GdaServerConnection * cnc,
+ gchar * where);
+
+
+gboolean gda_sybase_messages_install (GdaServerConnection *);
+void gda_sybase_messages_uninstall (GdaServerConnection *);
+
+gboolean sybase_chkerr (GdaError *,
+ GdaServerRecordset *,
+ GdaServerConnection *,
+ GdaServerCommand *,
+ gchar *);
+
+/* CS_RETCODE sybase_exec_chk (CS_RETCODE *, */
+/* CS_RETCODE, */
+/* GdaError *, */
+/* GdaServerRecordset *, */
+/* GdaServerConnection *, */
+/* GdaServerCommand *, gchar *); */
+
+/* #ifdef SYBASE_DEBUG */
+/* #define SYB_CHK(retptr, retcode, err, rec, cnc, cmd) \ */
+/* sybase_exec_chk(retptr, retcode, err, rec, cnc, cmd, \ */
+/* g_strdup_printf("%s at line %d (%s): ", __FILE__, __LINE__, \ */
+/* __PRETTY_FUNCTION__)) */
+/* #else */
+/* #define SYB_CHK(retptr, retcode, err, rec, cnc, cmd) \ */
+/* sybase_exec_chk(retptr, retcode, err, rec, cnc, cmd, \ */
+/* __PRETTY_FUNCTION__) */
+/* #endif */
+
+/* void gda_sybase_messages_handle (GdaError *, */
+/* GdaServerRecordset *, */
+/* GdaServerConnection *, */
+/* gchar * where); */
+
+
+gboolean gda_sybase_messages_handle_clientmsg (GdaError *,
+ GdaServerRecordset *,
+ GdaServerConnection *,
+ gchar * where);
+
+gboolean gda_sybase_messages_handle_servermsg (GdaError *,
+ GdaServerRecordset *,
+ GdaServerConnection *,
+ gchar * where);
+gboolean gda_sybase_messages_handle_csmsg (GdaError *,
+ GdaServerRecordset *,
+ GdaServerConnection *,
+ gchar * where);
+
+
+// Don't forget to FREE the results :-)
+gchar *g_sprintf_clientmsg (const gchar *,
+ CS_CLIENTMSG *);
+gchar *g_sprintf_servermsg (const gchar *,
+ CS_SERVERMSG *);
+
+void gda_sybase_log_clientmsg (const gchar *,
+ CS_CLIENTMSG *);
+void gda_sybase_log_servermsg (const gchar *,
+ CS_SERVERMSG *);
+
+void gda_sybase_debug_msg (gchar *);
+
+#endif
Index: gda-sybase-recordset.c
===================================================================
RCS file: /cvs/gnome/libgda/providers/gda-sybase-server/Attic/gda-sybase-recordset.c,v
retrieving revision 1.4.4.1
diff -u -u -r1.4.4.1 gda-sybase-recordset.c
--- gda-sybase-recordset.c 2001/09/16 20:12:39 1.4.4.1
+++ gda-sybase-recordset.c 2001/11/22 04:42:51
@@ -55,466 +55,552 @@
void
gda_sybase_field_fill_values (GdaServerRecordset * rec,
- sybase_Recordset * srec)
+ sybase_Recordset * srec)
{
- CS_INT i = 0;
- GList *entry = NULL;
+ CS_INT i = 0;
+ GList *entry = NULL;
- // g_return_if_fail(rec != NULL);
- // g_return_if_fail(srec != NULL);
- // g_return_if_fail(srec->data != NULL);
- // g_return_if_fail(srec->colscnt > 0);
-
- for (i = 0; i < srec->colscnt; i++) {
- entry = g_list_nth (gda_server_recordset_get_fields (rec), i);
- if (entry) {
- GdaServerField *field =
- (GdaServerField *) entry->data;
- if (field) {
- if (srec->data[i].data) {
- switch (gda_server_field_get_sql_type
- (field)) {
- case CS_IMAGE_TYPE:
- case CS_LONGBINARY_TYPE:
- case CS_BINARY_TYPE:
- case CS_VARBINARY_TYPE:
- gda_server_field_set_varbin
- (field,
- srec->data[i].data,
- srec->data[i].
- datalen);
- break;
- case CS_LONGCHAR_TYPE:
- srec->data[i].data[srec->
- data[i].
- datalen] =
- '\0';
- gda_server_field_set_longvarchar
- (field,
- srec->data[i].data);
- gda_server_field_set_actual_length
- (field,
- srec->data[i].
- datalen);
- break;
- case CS_CHAR_TYPE:
- case CS_VARCHAR_TYPE:
- case CS_TEXT_TYPE:
- srec->data[i].data[srec->
- data[i].
- datalen] =
- '\0';
- gda_server_field_set_varchar
- (field,
- (gchar *) srec->
- data[i].data);
- gda_server_field_set_actual_length
- (field,
- srec->data[i].
- datalen);
- break;
- case CS_BIT_TYPE:
- gda_server_field_set_boolean
- (field,
- (gboolean) *
- srec->data[i].data);
- break;
- case CS_TINYINT_TYPE:
- case CS_SMALLINT_TYPE:
- gda_server_field_set_smallint
- (field,
- (gshort) *
- srec->data[i].data);
- break;
- case CS_INT_TYPE:
- gda_server_field_set_integer
- (field,
- (gint) *
- srec->data[i].data);
- break;
- case CS_REAL_TYPE:
- gda_server_field_set_single
- (field,
- (gdouble) *
- srec->data[i].data);
- break;
- case CS_FLOAT_TYPE:
- gda_server_field_set_double
- (field,
- (gdouble) *
- srec->data[i].data);
- break;
- case CS_DATETIME_TYPE:
- gda_sybase_field_set_datetime
- (field,
- (CS_DATETIME *)
- srec->data[i].data);
- break;
- case CS_DATETIME4_TYPE:
- gda_sybase_field_set_datetime4
- (field,
- (CS_DATETIME4 *)
- srec->data[i].data);
- break;
- default:
- // try cs_convert data to CS_CHAR_TYPE
- gda_sybase_field_set_general
- (field,
- &srec->data[i],
- srec->scnc);
- break;
- }
+ // g_return_if_fail(rec != NULL);
+ // g_return_if_fail(srec != NULL);
+ // g_return_if_fail(srec->data != NULL);
+ // g_return_if_fail(srec->colscnt > 0);
+
+ for (i = 0; i < srec->colscnt; i++) {
+ entry = g_list_nth (gda_server_recordset_get_fields (rec), i);
+ if (entry) {
+ GdaServerField *field = (GdaServerField *) entry->data;
+ if (field) {
+ if (srec->data[i].data) {
+ switch (gda_server_field_get_sql_type
+ (field)) {
+ case CS_IMAGE_TYPE:
+ case CS_LONGBINARY_TYPE:
+ case CS_BINARY_TYPE:
+ case CS_VARBINARY_TYPE:
+ gda_server_field_set_varbin
+ (field,
+ srec->data[i].data,
+ srec->data[i].datalen);
+ break;
+ case CS_LONGCHAR_TYPE:
+ srec->data[i].data[srec->
+ data[i].
+ datalen] ='\0';
+ gda_server_field_set_longvarchar
+ (field,
+ srec->data[i].data);
+ gda_server_field_set_actual_length
+ (field,
+ srec->data[i].
+ datalen);
+ break;
+ case CS_CHAR_TYPE:
+ case CS_VARCHAR_TYPE:
+ case CS_TEXT_TYPE:
+ srec->data[i].data[srec->
+ data[i].
+ datalen] = '\0';
+ gda_server_field_set_varchar
+ (field,
+ (gchar *) srec->
+ data[i].data);
+ gda_server_field_set_actual_length
+ (field,
+ srec->data[i].
+ datalen);
+ break;
+ case CS_BIT_TYPE:
+ gda_server_field_set_boolean
+ (field,
+ (gboolean) *
+ srec->data[i].data);
+ break;
+ case CS_TINYINT_TYPE:
+ case CS_SMALLINT_TYPE:
+ gda_server_field_set_smallint
+ (field,
+ (gshort) *
+ srec->data[i].data);
+ break;
+ case CS_INT_TYPE:
+ gda_server_field_set_integer
+ (field,
+ (gint) *
+ srec->data[i].data);
+ break;
+ case CS_REAL_TYPE:
+ gda_server_field_set_single
+ (field,
+ (gdouble) *
+ srec->data[i].data);
+ break;
+ case CS_FLOAT_TYPE:
+ gda_server_field_set_double
+ (field,
+ (gdouble) *
+ srec->data[i].data);
+ break;
+ case CS_DATETIME_TYPE:
+ gda_sybase_field_set_datetime
+ (field,
+ (CS_DATETIME *)
+ srec->data[i].data);
+ break;
+ case CS_DATETIME4_TYPE:
+ gda_sybase_field_set_datetime4
+ (field,
+ (CS_DATETIME4 *)
+ srec->data[i].data);
+ break;
+ default:
+ // try cs_convert data to CS_CHAR_TYPE
+ gda_sybase_field_set_general
+ (field,
+ &srec->data[i],
+ srec->scnc);
+ break;
+ }
+ }
+ else {
+ gda_server_field_set_actual_length
+ (field, 0);
+ }
+ }
}
- else {
- gda_server_field_set_actual_length
- (field, 0);
- }
- }
}
- }
}
gint
gda_sybase_row_result (gboolean forward,
- GdaServerRecordset * recset,
- sybase_Recordset * srecset, CS_COMMAND * cmd)
+ GdaServerRecordset * recset,
+ sybase_Recordset * srecset,
+ CS_COMMAND * cmd)
{
- CS_INT rows_read = 0;
- // We are are just called within internal procedures and trust
- // them giving no null pointers
-
- // FIXME: check if previous row fetch is implementable
-
- if (srecset->failed == TRUE) {
- gda_server_recordset_set_at_begin (recset, FALSE);
- gda_server_recordset_set_at_end (recset, TRUE);
- return 1;
- }
+ CS_RETCODE ret;
+ CS_INT rows_read = 0;
+ // We are are just called within internal procedures and trust
+ // them giving no null pointers
+
+ // FIXME: check if previous row fetch is implementable
+
+ if (srecset->failed == TRUE) {
+ gda_server_recordset_set_at_begin (recset, FALSE);
+ gda_server_recordset_set_at_end (recset, TRUE);
+ return 1;
+ }
+
+
+ /* if this is true, data was returned from the query*/
+ if (srecset->recordSetRowStatus == SYBASE_DATA_RETURNED)
+ {
+ srecset->ret =
+ ct_fetch (cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read);
+
+ sybase_chkerr(NULL,
+ recset,
+ srecset->cnc,
+ srecset->cmd,
+ __PRETTY_FUNCTION__);
+
+ switch (srecset->ret)
+ {
+ case CS_SUCCEED:
+ gda_sybase_field_fill_values (recset, srecset);
+ srecset->rows_cnt += rows_read;
+ return 0;
+ break;
+ case CS_ROW_FAIL:
+ gda_log_error (_("fetch error at row %d"), srecset->rows_cnt);
+ srecset->rows_cnt += rows_read;
+ return 0;
+ break;
+ case CS_END_DATA:
+ gda_server_recordset_set_at_begin (recset, FALSE);
+ gda_server_recordset_set_at_end (recset, TRUE);
+ gda_log_message (_("CS_END_DATA on row %d; canceling"),
+ srecset->rows_cnt);
+ /* SYB_CHK ((CS_INT *) & srecset->ret, */
+ /* ct_cancel (NULL, cmd, CS_CANCEL_ALL), */
+ /* NULL, recset, srecset->cnc, srecset->cmd); */
+
+
+ gda_sybase_debug_msg("i'm in CS_END_DATA in gda_sybase_row_result");
+
+ srecset->ret = ct_cancel (NULL, cmd, CS_CANCEL_ALL);
+
+/* if (srecset->ret != CS_SUCCEED) */
+
+ sybase_chkerr(NULL,
+ recset,
+ srecset->cnc,
+ srecset->cmd,
+ __PRETTY_FUNCTION__);
+ return 1;
+ break;
+ default:
+
+
+ gda_sybase_debug_msg("i'm in default in gda_sybase_row_result");
+
+ gda_log_error (_("%s: Error (%d)"), __PRETTY_FUNCTION__,
+ srecset->ret);
+ gda_server_recordset_set_at_begin (recset, FALSE);
+ gda_server_recordset_set_at_end (recset, TRUE);
+ srecset->ret = ct_cancel (NULL, cmd, CS_CANCEL_ALL);
+
+ sybase_chkerr(NULL,
+ recset,
+ srecset->cnc,
+ srecset->cmd,
+ __PRETTY_FUNCTION__);
+ return -1;
+ break;
+ }
+ }
+ /* else, no data was returned from the query..*/
+ else
+ {
+ return 1;
+ }
- srecset->ret =
- ct_fetch (cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read);
- switch (srecset->ret) {
- case CS_SUCCEED:
- gda_sybase_field_fill_values (recset, srecset);
- srecset->rows_cnt += rows_read;
- return 0;
- break;
- case CS_ROW_FAIL:
- gda_log_error (_("fetch error at row %d"), srecset->rows_cnt);
- srecset->rows_cnt += rows_read;
- return 0;
- break;
- case CS_END_DATA:
- gda_server_recordset_set_at_begin (recset, FALSE);
- gda_server_recordset_set_at_end (recset, TRUE);
- gda_log_message (_("CS_END_DATA on row %d; canceling"),
- srecset->rows_cnt);
- SYB_CHK ((CS_INT *) & srecset->ret,
- ct_cancel (NULL, cmd, CS_CANCEL_ALL),
- NULL, recset, srecset->cnc, srecset->cmd);
- return 1;
- break;
- default:
- gda_log_error (_("%s: Error (%d)"), __PRETTY_FUNCTION__,
- srecset->ret);
- gda_server_recordset_set_at_begin (recset, FALSE);
- gda_server_recordset_set_at_end (recset, TRUE);
- srecset->ret = ct_cancel (NULL, cmd, CS_CANCEL_ALL);
- return -1;
- break;
- }
}
gboolean
gda_sybase_recordset_new (GdaServerRecordset * recset)
{
- sybase_Recordset *srecset = NULL;
+ sybase_Recordset *srecset = NULL;
- g_return_val_if_fail (recset != NULL, FALSE);
- srecset = g_new0 (sybase_Recordset, 1);
- g_return_val_if_fail (srecset != NULL, FALSE);
+ g_return_val_if_fail (recset != NULL, FALSE);
+ srecset = g_new0 (sybase_Recordset, 1);
+ g_return_val_if_fail (srecset != NULL, FALSE);
- srecset->colscnt = 0;
- srecset->failed = FALSE;
- srecset->scnc = (sybase_Connection *) NULL;
- srecset->scmd = (sybase_Command *) NULL;
+ srecset->colscnt = 0;
+ srecset->failed = FALSE;
+ srecset->scnc = (sybase_Connection *) NULL;
+ srecset->scmd = (sybase_Command *) NULL;
- /* We don't know the rowcount yet, so we initialize with null pointer */
- srecset->datafmt = (CS_DATAFMT *) NULL;
- srecset->data = (sybase_Field *) NULL;
+ /* We don't know the rowcount yet, so we initialize with null pointer */
+ srecset->datafmt = (CS_DATAFMT *) NULL;
+ srecset->data = (sybase_Field *) NULL;
- gda_server_recordset_set_user_data (recset, (gpointer) srecset);
+ gda_server_recordset_set_user_data (recset, (gpointer) srecset);
- return TRUE;
+ return TRUE;
}
gint
gda_sybase_recordset_move_next (GdaServerRecordset * recset)
{
- sybase_Recordset *srecset = NULL;
- CS_COMMAND *cmd = NULL;
- gint ret = 0;
-
- g_return_val_if_fail (recset != NULL, -1);
- srecset =
- (sybase_Recordset *)
- gda_server_recordset_get_user_data (recset);
- g_return_val_if_fail (srecset != NULL, -1);
- g_return_val_if_fail (srecset->scmd != NULL, -1);
- cmd = srecset->scmd->cmd;
- g_return_val_if_fail (cmd != NULL, -1);
-
- switch (srecset->result_type) {
- case CS_ROW_RESULT:
- case CS_CURSOR_RESULT:
- if ((ret = gda_sybase_row_result (TRUE, recset, srecset, cmd))
- == 0) {
- gda_server_recordset_set_at_begin (recset, FALSE);
- return 0;
- }
- else {
- gda_server_recordset_set_at_end (recset, TRUE);
- return 1;
+ sybase_Recordset *srecset = NULL;
+ CS_COMMAND *cmd = NULL;
+ gint ret = 0;
+ CS_RETCODE ret2;
+
+ g_return_val_if_fail (recset != NULL, -1);
+ srecset =
+ (sybase_Recordset *)
+ gda_server_recordset_get_user_data (recset);
+ g_return_val_if_fail (srecset != NULL, -1);
+ g_return_val_if_fail (srecset->scmd != NULL, -1);
+ cmd = srecset->scmd->cmd;
+ g_return_val_if_fail (cmd != NULL, -1);
+
+ switch (srecset->result_type) {
+ case CS_ROW_RESULT:
+ case CS_CURSOR_RESULT:
+ if ((ret = gda_sybase_row_result (TRUE, recset, srecset, cmd))
+ == 0) {
+ gda_server_recordset_set_at_begin (recset, FALSE);
+ return 0;
+ }
+ else {
+ gda_server_recordset_set_at_end (recset, TRUE);
+ return 1;
+ }
+ break;
+ case CS_ROW_FAIL:
+ return -1;
+ break;
+ default:
+ gda_log_message ("%s: %d", __PRETTY_FUNCTION__, srecset->ret);
+
+ /* SYB_CHK ((CS_INT *) & srecset->scnc->ret, */
+ /* ct_cancel (NULL, cmd, CS_CANCEL_ALL), */
+ /* NULL, recset, srecset->cnc, srecset->cmd); */
+
+ ret2 = ct_cancel (NULL, cmd, CS_CANCEL_ALL);
+
+/* if (ret2 != CS_SUCCEED) */
+ sybase_chkerr(NULL,
+ recset,
+ srecset->cnc,
+ srecset->cmd,
+ __PRETTY_FUNCTION__);
+ gda_server_recordset_set_at_begin (recset, FALSE);
+ gda_server_recordset_set_at_end (recset, TRUE);
+ return -1;
+ break;
}
- break;
- case CS_ROW_FAIL:
- return -1;
- break;
- default:
- gda_log_message ("%s: %d", __PRETTY_FUNCTION__, srecset->ret);
- SYB_CHK ((CS_INT *) & srecset->scnc->ret,
- ct_cancel (NULL, cmd, CS_CANCEL_ALL),
- NULL, recset, srecset->cnc, srecset->cmd);
+
gda_server_recordset_set_at_begin (recset, FALSE);
gda_server_recordset_set_at_end (recset, TRUE);
return -1;
- break;
- }
-
- gda_server_recordset_set_at_begin (recset, FALSE);
- gda_server_recordset_set_at_end (recset, TRUE);
- return -1;
}
gint
gda_sybase_recordset_move_prev (GdaServerRecordset * recset)
{
- g_return_val_if_fail (recset != NULL, -1);
- gda_server_recordset_set_at_begin (recset, FALSE);
- gda_server_recordset_set_at_end (recset, TRUE);
+ g_return_val_if_fail (recset != NULL, -1);
+ gda_server_recordset_set_at_begin (recset, FALSE);
+ gda_server_recordset_set_at_end (recset, TRUE);
- return 1;
+ return 1;
}
gint
gda_sybase_recordset_close (GdaServerRecordset * recset)
{
- sybase_Recordset *srecset = NULL;
- CS_INT colnr = 0;
+ sybase_Recordset *srecset = NULL;
+ CS_INT colnr = 0;
- g_return_val_if_fail (recset != NULL, -1);
- srecset = gda_server_recordset_get_user_data (recset);
- g_return_val_if_fail (srecset != NULL, -1);
-
- if (srecset->data) {
- while (colnr < srecset->colscnt) {
- if (srecset->data[colnr].data) {
- g_free ((gpointer) srecset->data[colnr].data);
- }
- colnr++;
+ g_return_val_if_fail (recset != NULL, -1);
+ srecset = gda_server_recordset_get_user_data (recset);
+ g_return_val_if_fail (srecset != NULL, -1);
+
+ if (srecset->data) {
+ while (colnr < srecset->colscnt) {
+ if (srecset->data[colnr].data) {
+ g_free ((gpointer) srecset->data[colnr].data);
+ }
+ colnr++;
+ }
+ g_free ((gpointer) srecset->data);
}
- g_free ((gpointer) srecset->data);
- }
- if (srecset->datafmt != NULL) {
- g_free ((gpointer) srecset->datafmt);
- }
+ if (srecset->datafmt != NULL) {
+ g_free ((gpointer) srecset->datafmt);
+ }
- return 0;
+ return 0;
}
void
gda_sybase_recordset_free (GdaServerRecordset * recset)
{
- sybase_Recordset *srecset = NULL;
- CS_INT colnr = 0;
+ sybase_Recordset *srecset = NULL;
+ CS_INT colnr = 0;
- g_return_if_fail (recset != NULL);
- srecset = gda_server_recordset_get_user_data (recset);
- g_return_if_fail (srecset != NULL);
-
- if (srecset->data) {
- while (colnr < srecset->colscnt) {
- if (srecset->data[colnr].data) {
- g_free ((gpointer) srecset->data[colnr].data);
- }
- colnr++;
+ g_return_if_fail (recset != NULL);
+ srecset = gda_server_recordset_get_user_data (recset);
+ g_return_if_fail (srecset != NULL);
+
+ if (srecset->data) {
+ while (colnr < srecset->colscnt) {
+ if (srecset->data[colnr].data) {
+ g_free ((gpointer) srecset->data[colnr].data);
+ }
+ colnr++;
+ }
+ g_free ((gpointer) srecset->data);
}
- g_free ((gpointer) srecset->data);
- }
- if (srecset->datafmt != NULL) {
- g_free ((gpointer) srecset->datafmt);
- }
- g_free ((gpointer) srecset);
+ if (srecset->datafmt != NULL) {
+ g_free ((gpointer) srecset->datafmt);
+ }
+ g_free ((gpointer) srecset);
- gda_server_recordset_set_user_data (recset, (gpointer) NULL);
+ gda_server_recordset_set_user_data (recset, (gpointer) NULL);
}
void
gda_sybase_init_recset_fields (GdaError * err,
- GdaServerRecordset * recset,
- sybase_Recordset * srecset,
- CS_RETCODE result_type)
+ GdaServerRecordset * recset,
+ sybase_Recordset * srecset,
+ CS_RETCODE result_type,
+ GdaServerConnection *cnc)
{
- gint colnr;
- CS_RETCODE ret = CS_SUCCEED;
- CS_DATAFMT *datafmt = NULL;
-
- g_return_if_fail (recset != NULL);
- g_return_if_fail (srecset != NULL);
- g_return_if_fail (srecset->scmd != NULL);
- g_return_if_fail (srecset->scmd->cmd != NULL);
- g_return_if_fail (srecset->scnc != NULL);
- g_return_if_fail (srecset->scnc->cnc != NULL);
- /* Yes we mean ==, because we don't want to overwrite any existing data */
- g_return_if_fail (srecset->data == NULL);
-
- srecset->ret = result_type;
- srecset->rows_cnt = 0;
-
- // Count columns
- if (SYB_CHK ((CS_INT *) & srecset->scnc->ret,
- ct_res_info (srecset->scmd->cmd, CS_NUMDATA,
- &srecset->colscnt, CS_UNUSED, NULL),
- err, recset, srecset->cnc, srecset->cmd) != CS_SUCCEED) {
- gda_log_error (_("Failed fetching # of columns"));
- gda_server_recordset_free (recset);
- recset = NULL;
- return;
-#ifdef SYBASE_DEBUG
- }
- else {
- gda_log_message (_("Counted %d columns"), srecset->colscnt);
-#endif
- }
+ gint colnr;
+ CS_RETCODE ret = CS_SUCCEED;
+ CS_RETCODE ret2;
+ CS_DATAFMT *datafmt = NULL;
+ gchar *message;
+
- // allocate datafmt structure for colscnt columns
- srecset->datafmt = g_new0 (CS_DATAFMT, srecset->colscnt);
- if (!srecset->datafmt) {
- gda_log_error (_("%s could not allocate datafmt info"),
- __PRETTY_FUNCTION__);
- gda_server_recordset_free (recset);
- return;
- }
-
- // allocate data structure for colscnt columns
- if (!srecset->data) {
- srecset->data = g_new0 (sybase_Field, srecset->colscnt);
+
+
+ g_return_if_fail (recset != NULL);
+ g_return_if_fail (srecset != NULL);
+ g_return_if_fail (srecset->scmd != NULL);
+ g_return_if_fail (srecset->scmd->cmd != NULL);
+ g_return_if_fail (srecset->scnc != NULL);
+ g_return_if_fail (srecset->scnc->cnc != NULL);
+ /* Yes we mean ==, because we don't want to overwrite any existing data */
+ g_return_if_fail (srecset->data == NULL);
+
+ srecset->ret = result_type;
+ srecset->rows_cnt = 0;
+
+
+ gda_sybase_debug_msg("in the init recset fields");
+
+ /* initialize the row index */
+ srecset->index = 0;
+
+ // Count columns
+ /* if (SYB_CHK ((CS_INT *) & srecset->scnc->ret, */
+ /* ct_res_info (srecset->scmd->cmd, CS_NUMDATA, */
+ /* &srecset->colscnt, CS_UNUSED, NULL), */
+ /* err, recset, srecset->cnc, srecset->cmd) != CS_SUCCEED) { */
+
+ ret2 = ct_res_info (srecset->scmd->cmd,
+ CS_NUMDATA,
+ &srecset->colscnt,
+ CS_UNUSED,
+ NULL);
+
+ sybase_chkerr(err,recset,cnc,NULL,__PRETTY_FUNCTION__);
+
+
+
+ if (ret2 != CS_SUCCEED)
+ {
+ gda_log_error (_("Failed fetching # of columns"));
+
+ gda_sybase_debug_msg("can not figure out the # of columns");
+
+ gda_server_recordset_free (recset);
+ recset = NULL;
+ return;
+ }
+
+ else
+ {
+ message = g_new0(gchar,500);
+ g_snprintf(message,499,"the colcount is %d",srecset->colscnt);
+ gda_sybase_debug_msg(message);
+ g_free(message);
+ }
+
+
+ // allocate datafmt structure for colscnt columns
+ srecset->datafmt = g_new0 (CS_DATAFMT, srecset->colscnt);
+ if (!srecset->datafmt) {
+ gda_log_error (_("%s could not allocate datafmt info"),
+ __PRETTY_FUNCTION__);
+
+ gda_sybase_debug_msg(" I just can't allocate CS_DATAFMT");
+
+ gda_server_recordset_free (recset);
+ return;
+ }
+
+ // allocate data structure for colscnt columns
if (!srecset->data) {
- gda_log_error (_("%s could not allocate data fields"),
- __PRETTY_FUNCTION__);
- gda_server_recordset_free (recset);
- return;
+ srecset->data = g_new0 (sybase_Field, srecset->colscnt);
+ if (!srecset->data) {
+ gda_log_error (_("%s could not allocate data fields"),
+ __PRETTY_FUNCTION__);
+ gda_server_recordset_free (recset);
+ return;
+ }
}
- }
- /* set sybase's resulttype */
- srecset->result_type = result_type;
- srecset->failed = FALSE;
- datafmt = srecset->datafmt;
+ /* set sybase's resulttype */
+ srecset->result_type = result_type;
+ srecset->failed = FALSE;
+ datafmt = srecset->datafmt;
- for (colnr = 0; colnr < srecset->colscnt; colnr++) {
- GdaServerField *field;
+ for (colnr = 0; colnr < srecset->colscnt; colnr++) {
+ GdaServerField *field;
- // Initialize user data fmt pointer to datafmt pointer for colnr
- srecset->data[colnr].fmt = &srecset->datafmt[colnr];
+ // Initialize user data fmt pointer to datafmt pointer for colnr
+ srecset->data[colnr].fmt = &srecset->datafmt[colnr];
#ifdef SYBASE_DEBUG
- gda_log_message (_("ct_describe on col # %d"), colnr + 1);
+ gda_log_message (_("ct_describe on col # %d"), colnr + 1);
#endif
- // get datafmt info for colnr
- ret = ct_describe (srecset->scmd->cmd, colnr + 1,
- &srecset->datafmt[colnr]);
- if (ret != CS_SUCCEED) {
- gda_log_error (_("ct_describe on col # %d failed"),
- colnr + 1);
- srecset->failed = TRUE;
- return;
- }
+ // get datafmt info for colnr
+ ret = ct_describe (srecset->scmd->cmd, colnr + 1,
+ &srecset->datafmt[colnr]);
+ if (ret != CS_SUCCEED) {
+ gda_log_error (_("ct_describe on col # %d failed"),
+ colnr + 1);
+ srecset->failed = TRUE;
+ return;
+ }
#ifdef SYBASE_DEBUG
- gda_log_message (_("ct_describe(%d): '%s', %d (%s)"),
- colnr + 1, datafmt[colnr].name,
- datafmt[colnr].datatype,
- sybase_get_type_name (datafmt[colnr].
- datatype));
+ gda_log_message (_("ct_describe(%d): '%s', %d (%s)"),
+ colnr + 1, datafmt[colnr].name,
+ datafmt[colnr].datatype,
+ sybase_get_type_name (datafmt[colnr].
+ datatype));
#endif
- // allocate enough memory for column colnr
- srecset->data[colnr].data = g_new0 (gchar,
- srecset->datafmt[colnr].
- maxlength + 1);
- if (!srecset->data[colnr].data) {
- gda_log_error (_("could not allocate data holder"));
- srecset->failed = TRUE;
- return;
- }
-
- // bind column data placeholder to column colnr
- ret = ct_bind (srecset->scmd->cmd, (colnr + 1),
- &datafmt[colnr], srecset->data[colnr].data,
- &srecset->data[colnr].datalen,
- (CS_SMALLINT *) & srecset->data[colnr].
- indicator);
- if (ret != CS_SUCCEED) {
- gda_log_error (_
- ("could not ct_bind data holder to column"));
- srecset->failed = TRUE;
- return;
- }
+ // allocate enough memory for column colnr
+ srecset->data[colnr].data = g_new0 (gchar,
+ srecset->datafmt[colnr].
+ maxlength + 1);
+ if (!srecset->data[colnr].data) {
+ gda_log_error (_("could not allocate data holder"));
+ srecset->failed = TRUE;
+ return;
+ }
- // check if we got an illegal sql type, exit in that case
- if (datafmt[colnr].datatype == CS_ILLEGAL_TYPE) {
- gda_log_error (_("illegal type detected, aborting"));
- srecset->failed = TRUE;
- return;
- }
- else { /* well, let's allocate and fill in fielddata of column colnr */
- field = gda_server_field_new ();
- if (!field) {
- gda_log_error (_("could not allocate field"));
- srecset->failed = TRUE;
- return;
- }
+ // bind column data placeholder to column colnr
+ ret = ct_bind (srecset->scmd->cmd, (colnr + 1),
+ &datafmt[colnr], srecset->data[colnr].data,
+ &srecset->data[colnr].datalen,
+ (CS_SMALLINT *) & srecset->data[colnr].
+ indicator);
+ if (ret != CS_SUCCEED) {
+ gda_log_error (_
+ ("could not ct_bind data holder to column"));
+ srecset->failed = TRUE;
+ return;
+ }
- gda_server_field_set_name (field,
- datafmt[colnr].name);
- gda_server_field_set_sql_type (field,
- datafmt[colnr].
- datatype);
- gda_server_field_set_actual_length (field,
- srecset->
- data[colnr].
- datalen);
- gda_server_field_set_defined_length (field,
- datafmt[colnr].
- maxlength);
- gda_server_field_set_user_data (field,
- (gpointer) & srecset->
- data[colnr]);
- gda_server_field_set_scale (field,
- datafmt[colnr].scale);
- // FIXME:
- // datafmt[colnr].precision: no corresponding function
+ // check if we got an illegal sql type, exit in that case
+ if (datafmt[colnr].datatype == CS_ILLEGAL_TYPE) {
+ gda_log_error (_("illegal type detected, aborting"));
+ srecset->failed = TRUE;
+ return;
+ }
+ else { /* well, let's allocate and fill in fielddata of column colnr */
+ field = gda_server_field_new ();
+ if (!field) {
+ gda_log_error (_("could not allocate field"));
+ srecset->failed = TRUE;
+ return;
+ }
+
+ gda_server_field_set_name (field,
+ datafmt[colnr].name);
+ gda_server_field_set_sql_type (field,
+ datafmt[colnr].
+ datatype);
+ gda_server_field_set_actual_length (field,
+ srecset->
+ data[colnr].
+ datalen);
+ gda_server_field_set_defined_length (field,
+ datafmt[colnr].
+ maxlength);
+ gda_server_field_set_user_data (field,
+ (gpointer) & srecset->
+ data[colnr]);
+ gda_server_field_set_scale (field,
+ datafmt[colnr].scale);
+ // FIXME:
+ // datafmt[colnr].precision: no corresponding function
- // and add it to the recordset
- gda_server_recordset_add_field (recset, field);
+ // and add it to the recordset
+ gda_server_recordset_add_field (recset, field);
+ }
}
- }
- // srecset->ret = ct_fetch(srecset->scmd->cmd, CS_UNUSED, CS_UNUSED, CS_NULLTERM,
- // &srecset->rows_cnt);
+ // srecset->ret = ct_fetch(srecset->scmd->cmd, CS_UNUSED, CS_UNUSED, CS_NULLTERM,
+ // &srecset->rows_cnt);
- // gda_sybase_field_fill_values(recset, srecset);
+ // gda_sybase_field_fill_values(recset, srecset);
}
Index: gda-sybase-recordset.h
===================================================================
RCS file: /cvs/gnome/libgda/providers/gda-sybase-server/Attic/gda-sybase-recordset.h,v
retrieving revision 1.3.4.1
diff -u -u -r1.3.4.1 gda-sybase-recordset.h
--- gda-sybase-recordset.h 2001/09/16 20:12:39 1.3.4.1
+++ gda-sybase-recordset.h 2001/11/22 04:42:51
@@ -37,6 +37,14 @@
* Per-object specific structures
*/
+
+typedef gint setStatus;
+
+#define SYBASE_DATA_RETURNED (setStatus) 1
+#define SYBASE_NO_DATA_RETURNED (setStatus) 0
+#define SYBASE_NO_DATA_RETURNED (setStatus) 0
+
+
typedef struct _sybase_Field
{
CS_INT indicator;
@@ -48,21 +56,29 @@
typedef struct _sybase_Recordset
{
- GdaServerConnection *cnc;
- GdaServerCommand *cmd;
- sybase_Connection *scnc;
- sybase_Command *scmd;
-
- CS_RETCODE ret;
- CS_RETCODE result_type;
- CS_INT rows_cnt;
- gboolean failed;
- CS_INT colscnt;
- CS_DATAFMT *datafmt;
- sybase_Field *data;
+ GdaServerConnection *cnc;
+ GdaServerCommand *cmd;
+ sybase_Connection *scnc;
+ sybase_Command *scmd;
+
+ CS_RETCODE ret;
+ CS_RETCODE result_type;
+ CS_INT rows_cnt;
+ gboolean failed;
+ CS_INT colscnt;
+ CS_DATAFMT *datafmt;
+ sybase_Field *data;
+
+ CS_INT index;
+ setStatus recordSetRowStatus;
+
+
}
sybase_Recordset;
+
+
+
gboolean gda_sybase_recordset_new (GdaServerRecordset *);
gint gda_sybase_recordset_move_next (GdaServerRecordset *);
gint gda_sybase_recordset_move_prev (GdaServerRecordset *);
@@ -71,7 +87,7 @@
void gda_sybase_init_recset_fields (GdaError *,
GdaServerRecordset *,
- sybase_Recordset *, CS_RETCODE);
+ sybase_Recordset *, CS_RETCODE, GdaServerConnection *);
void gda_sybase_field_fill_values (GdaServerRecordset *, sybase_Recordset *);
gint gda_sybase_row_result (gboolean forward,
Index: gda-sybase-types.c
===================================================================
RCS file: /cvs/gnome/libgda/providers/gda-sybase-server/Attic/gda-sybase-types.c,v
retrieving revision 1.3
diff -u -u -r1.3 gda-sybase-types.c
--- gda-sybase-types.c 2001/07/18 23:05:42 1.3
+++ gda-sybase-types.c 2001/11/22 04:42:52
@@ -1,215 +1,215 @@
-/*
- * $Id: gda-sybase-types.c,v 1.3 2001/07/18 23:05:42 vivien Exp $
- *
- * GNOME DB sybase Provider
- * Copyright (C) 2000 Rodrigo Moya
- * Copyright (C) 2000 Stephan Heinze
- * Copyright (C) 2000 Holger Thon
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-// $Log: gda-sybase-types.c,v $
-// Revision 1.3 2001/07/18 23:05:42 vivien
-// Ran indent -br -i8 on the files
-//
-// Revision 1.2 2001/04/07 08:49:31 rodrigo
-// 2001-04-07 Rodrigo Moya <rodrigo gnome-db org>
-//
-// * objects renaming (Gda_* to Gda*) to conform to the GNOME
-// naming standards
-//
-// Revision 1.1.1.1 2000/08/10 09:32:39 rodrigo
-// First version of libgda separated from GNOME-DB
-//
-// Revision 1.2 2000/08/04 11:36:30 rodrigo
-// Things I forgot in the last commit
-//
-// Revision 1.1 2000/08/04 10:20:37 rodrigo
-// New Sybase provider
-//
-//
-
-
-#include "gda-sybase.h"
-
-// NULL means we have no corresponding server type name
-// illegal type should always be last type
-const sybase_Types gda_sybase_type_list[GDA_SYBASE_TYPE_CNT] = {
- // Binary types
- {"binary", CS_BINARY_TYPE, GDA_TypeVarbin}, // 1
- {NULL, CS_LONGBINARY_TYPE, GDA_TypeLongvarbin}, // 2
- {"varbinary", CS_VARBINARY_TYPE, GDA_TypeVarbin}, // 3
- // Boolean types
- {"boolean", CS_BIT_TYPE, GDA_TypeBoolean}, // 4
- // Character types
- {"char", CS_CHAR_TYPE, GDA_TypeVarchar}, // 5
- {NULL, CS_LONGCHAR_TYPE, GDA_TypeLongvarchar}, // 6
- {"varchar", CS_VARCHAR_TYPE, GDA_TypeVarchar}, // 7
- // Datetime types
- {"datetime", CS_DATETIME_TYPE, GDA_TypeDbTimestamp}, // 8
- {"smalldatetime", CS_DATETIME4_TYPE, GDA_TypeDbTimestamp}, // 9
- // Numeric types
- {"tinyint", CS_TINYINT_TYPE, GDA_TypeSmallint}, // 10
- {"smallint", CS_SMALLINT_TYPE, GDA_TypeSmallint}, // 11
- {"int", CS_INT_TYPE, GDA_TypeInteger}, // 12
- {"decimal", CS_DECIMAL_TYPE, GDA_TypeDecimal}, // 13
- {"numeric", CS_NUMERIC_TYPE, GDA_TypeNumeric}, // 14
- {"float", CS_FLOAT_TYPE, GDA_TypeDouble}, // 15
- {"real", CS_REAL_TYPE, GDA_TypeSingle}, // 16
- {"text", CS_TEXT_TYPE, GDA_TypeLongvarchar}, // 17
- {"image", CS_IMAGE_TYPE, GDA_TypeVarbin}, // 18
-
- // Security types
- {"boundary", CS_BOUNDARY_TYPE, GDA_TypeVarbin}, // 19
- {"sensitivity", CS_SENSITIVITY_TYPE, GDA_TypeVarbin}, // 20
-
-// Types unsupported by gda-srv are reported as varchar and at the end
-// of this list
- // Money types
- {"money", CS_MONEY_TYPE, GDA_TypeVarchar}, // 21
- {"smallmoney", CS_MONEY4_TYPE, GDA_TypeVarchar}, // 22
- // { "money", CS_MONEY_TYPE, GDA_TypeCurrency }, // 21
- // { "smallmoney", CS_MONEY4_TYPE, GDA_TypeCurrency }, // 22
-
-
- {NULL, CS_ILLEGAL_TYPE, GDA_TypeNull} // 23
-};
-
-const gshort
-sybase_get_c_type (const GDA_ValueType gda_type)
-{
- // FIXME: implement c types
- return -1;
-}
-
-const GDA_ValueType
-sybase_get_gda_type (const CS_INT sql_type)
-{
- gint i = 0;
-
- while ((i < GDA_SYBASE_TYPE_CNT)) {
- if (gda_sybase_type_list[i].sql_type == sql_type) {
- return gda_sybase_type_list[i].gda_type;
- }
- i++;
- }
-
- return gda_sybase_type_list[GDA_SYBASE_TYPE_CNT - 1].gda_type;
-}
-
-const CS_INT
-sybase_get_sql_type (const GDA_ValueType gda_type)
-{
- gint i = 0;
-
- while ((i < GDA_SYBASE_TYPE_CNT)) {
- if (gda_sybase_type_list[i].gda_type == gda_type) {
- return gda_sybase_type_list[i].gda_type;
- }
- i++;
- }
-
- return gda_sybase_type_list[GDA_SYBASE_TYPE_CNT - 1].sql_type;
-}
-
-const gchar *
-sybase_get_type_name (const CS_INT sql_type)
-{
- gint i = 0;
-
- while ((i < GDA_SYBASE_TYPE_CNT)) {
- if (gda_sybase_type_list[i].sql_type == sql_type) {
- return gda_sybase_type_list[i].name;
- }
- i++;
- }
-
- return gda_sybase_type_list[GDA_SYBASE_TYPE_CNT - 1].name;
-}
-
-void
-gda_sybase_field_set_datetime (GdaServerField * field, CS_DATETIME * dt)
-{
- GDate *date;
- GTime time;
-
- date = g_date_new_dmy (1, 1, 1900);
- g_return_if_fail (date != NULL);
- g_date_add_days (date, (guint) dt->dtdays);
- time = (GTime) dt->dttime / 300;
- gda_server_field_set_timestamp (field, date, time);
- g_date_free (date);
-}
-
-void
-gda_sybase_field_set_datetime4 (GdaServerField * field, CS_DATETIME4 * dt)
-{
- GDate *date;
- GTime time;
-
- date = g_date_new_dmy (1, 1, 1900);
- g_return_if_fail (date != NULL);
- g_date_add_days (date, (guint) dt->days);
- time = (GTime) dt->minutes * 60;
- gda_server_field_set_timestamp (field, date, time);
- g_date_free (date);
-}
-
-#define SYBASE_CONVBUF_SIZE 1024
-
-void
-gda_sybase_field_set_general (GdaServerField * field,
- sybase_Field * sfield, sybase_Connection * scnc)
-{
- CS_DATAFMT destfmt;
- CS_RETCODE ret = CS_SUCCEED;
- CS_INT len = 0;
- gchar tmpdata[SYBASE_CONVBUF_SIZE];
-
- g_return_if_fail (field != NULL);
- g_return_if_fail (sfield != NULL);
- g_return_if_fail (sfield->data != NULL);
- g_return_if_fail (sfield->fmt != NULL);
- g_return_if_fail (scnc->ctx != NULL);
-
- if (sfield->indicator == CS_NULLDATA) {
- gda_server_field_set_actual_length (field, 0);
- return;
- }
-
- cs_will_convert (scnc->ctx, sfield->fmt->datatype, CS_CHAR_TYPE,
- &ret);
- if (ret != CS_TRUE) {
- gda_server_field_set_actual_length (field, 0);
- gda_log_message ("cslib cannot convert type %d",
- sfield->fmt->datatype);
- return;
- }
-
- destfmt.maxlength = SYBASE_CONVBUF_SIZE;
- destfmt.datatype = CS_CHAR_TYPE;
- destfmt.format = CS_FMT_NULLTERM;
- destfmt.locale = NULL;
-
- if (cs_convert (scnc->ctx, sfield->fmt, sfield->data, &destfmt,
- &tmpdata, &len) != CS_SUCCEED) {
- gda_server_field_set_actual_length (field, 0);
- return;
- }
-
- gda_server_field_set_varchar (field, (gchar *) & tmpdata);
- gda_server_field_set_actual_length (field, len - 1);
-}
+/*
+ * $Id: gda-sybase-types.c,v 1.3 2001/07/18 23:05:42 vivien Exp $
+ *
+ * GNOME DB sybase Provider
+ * Copyright (C) 2000 Rodrigo Moya
+ * Copyright (C) 2000 Stephan Heinze
+ * Copyright (C) 2000 Holger Thon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+// $Log: gda-sybase-types.c,v $
+// Revision 1.3 2001/07/18 23:05:42 vivien
+// Ran indent -br -i8 on the files
+//
+// Revision 1.2 2001/04/07 08:49:31 rodrigo
+// 2001-04-07 Rodrigo Moya <rodrigo gnome-db org>
+//
+// * objects renaming (Gda_* to Gda*) to conform to the GNOME
+// naming standards
+//
+// Revision 1.1.1.1 2000/08/10 09:32:39 rodrigo
+// First version of libgda separated from GNOME-DB
+//
+// Revision 1.2 2000/08/04 11:36:30 rodrigo
+// Things I forgot in the last commit
+//
+// Revision 1.1 2000/08/04 10:20:37 rodrigo
+// New Sybase provider
+//
+//
+
+
+#include "gda-sybase.h"
+
+// NULL means we have no corresponding server type name
+// illegal type should always be last type
+const sybase_Types gda_sybase_type_list[GDA_SYBASE_TYPE_CNT] = {
+ // Binary types
+ {"binary", CS_BINARY_TYPE, GDA_TypeVarbin}, // 1
+ {NULL, CS_LONGBINARY_TYPE, GDA_TypeLongvarbin}, // 2
+ {"varbinary", CS_VARBINARY_TYPE, GDA_TypeVarbin}, // 3
+ // Boolean types
+ {"boolean", CS_BIT_TYPE, GDA_TypeBoolean}, // 4
+ // Character types
+ {"char", CS_CHAR_TYPE, GDA_TypeVarchar}, // 5
+ {NULL, CS_LONGCHAR_TYPE, GDA_TypeLongvarchar}, // 6
+ {"varchar", CS_VARCHAR_TYPE, GDA_TypeVarchar}, // 7
+ // Datetime types
+ {"datetime", CS_DATETIME_TYPE, GDA_TypeDbTimestamp}, // 8
+ {"smalldatetime", CS_DATETIME4_TYPE, GDA_TypeDbTimestamp}, // 9
+ // Numeric types
+ {"tinyint", CS_TINYINT_TYPE, GDA_TypeSmallint}, // 10
+ {"smallint", CS_SMALLINT_TYPE, GDA_TypeSmallint}, // 11
+ {"int", CS_INT_TYPE, GDA_TypeInteger}, // 12
+ {"decimal", CS_DECIMAL_TYPE, GDA_TypeDecimal}, // 13
+ {"numeric", CS_NUMERIC_TYPE, GDA_TypeNumeric}, // 14
+ {"float", CS_FLOAT_TYPE, GDA_TypeDouble}, // 15
+ {"real", CS_REAL_TYPE, GDA_TypeSingle}, // 16
+ {"text", CS_TEXT_TYPE, GDA_TypeLongvarchar}, // 17
+ {"image", CS_IMAGE_TYPE, GDA_TypeVarbin}, // 18
+
+ // Security types
+ {"boundary", CS_BOUNDARY_TYPE, GDA_TypeVarbin}, // 19
+ {"sensitivity", CS_SENSITIVITY_TYPE, GDA_TypeVarbin}, // 20
+
+// Types unsupported by gda-srv are reported as varchar and at the end
+// of this list
+ // Money types
+ {"money", CS_MONEY_TYPE, GDA_TypeVarchar}, // 21
+ {"smallmoney", CS_MONEY4_TYPE, GDA_TypeVarchar}, // 22
+ // { "money", CS_MONEY_TYPE, GDA_TypeCurrency }, // 21
+ // { "smallmoney", CS_MONEY4_TYPE, GDA_TypeCurrency }, // 22
+
+
+ {NULL, CS_ILLEGAL_TYPE, GDA_TypeNull} // 23
+};
+
+const gshort
+sybase_get_c_type (const GDA_ValueType gda_type)
+{
+ // FIXME: implement c types
+ return -1;
+}
+
+const GDA_ValueType
+sybase_get_gda_type (const CS_INT sql_type)
+{
+ gint i = 0;
+
+ while ((i < GDA_SYBASE_TYPE_CNT)) {
+ if (gda_sybase_type_list[i].sql_type == sql_type) {
+ return gda_sybase_type_list[i].gda_type;
+ }
+ i++;
+ }
+
+ return gda_sybase_type_list[GDA_SYBASE_TYPE_CNT - 1].gda_type;
+}
+
+const CS_INT
+sybase_get_sql_type (const GDA_ValueType gda_type)
+{
+ gint i = 0;
+
+ while ((i < GDA_SYBASE_TYPE_CNT)) {
+ if (gda_sybase_type_list[i].gda_type == gda_type) {
+ return gda_sybase_type_list[i].gda_type;
+ }
+ i++;
+ }
+
+ return gda_sybase_type_list[GDA_SYBASE_TYPE_CNT - 1].sql_type;
+}
+
+const gchar *
+sybase_get_type_name (const CS_INT sql_type)
+{
+ gint i = 0;
+
+ while ((i < GDA_SYBASE_TYPE_CNT)) {
+ if (gda_sybase_type_list[i].sql_type == sql_type) {
+ return gda_sybase_type_list[i].name;
+ }
+ i++;
+ }
+
+ return gda_sybase_type_list[GDA_SYBASE_TYPE_CNT - 1].name;
+}
+
+void
+gda_sybase_field_set_datetime (GdaServerField * field, CS_DATETIME * dt)
+{
+ GDate *date;
+ GTime time;
+
+ date = g_date_new_dmy (1, 1, 1900);
+ g_return_if_fail (date != NULL);
+ g_date_add_days (date, (guint) dt->dtdays);
+ time = (GTime) dt->dttime / 300;
+ gda_server_field_set_timestamp (field, date, time);
+ g_date_free (date);
+}
+
+void
+gda_sybase_field_set_datetime4 (GdaServerField * field, CS_DATETIME4 * dt)
+{
+ GDate *date;
+ GTime time;
+
+ date = g_date_new_dmy (1, 1, 1900);
+ g_return_if_fail (date != NULL);
+ g_date_add_days (date, (guint) dt->days);
+ time = (GTime) dt->minutes * 60;
+ gda_server_field_set_timestamp (field, date, time);
+ g_date_free (date);
+}
+
+#define SYBASE_CONVBUF_SIZE 1024
+
+void
+gda_sybase_field_set_general (GdaServerField * field,
+ sybase_Field * sfield, sybase_Connection * scnc)
+{
+ CS_DATAFMT destfmt;
+ CS_RETCODE ret = CS_SUCCEED;
+ CS_INT len = 0;
+ gchar tmpdata[SYBASE_CONVBUF_SIZE];
+
+ g_return_if_fail (field != NULL);
+ g_return_if_fail (sfield != NULL);
+ g_return_if_fail (sfield->data != NULL);
+ g_return_if_fail (sfield->fmt != NULL);
+ g_return_if_fail (scnc->ctx != NULL);
+
+ if (sfield->indicator == CS_NULLDATA) {
+ gda_server_field_set_actual_length (field, 0);
+ return;
+ }
+
+ cs_will_convert (scnc->ctx, sfield->fmt->datatype, CS_CHAR_TYPE,
+ &ret);
+ if (ret != CS_TRUE) {
+ gda_server_field_set_actual_length (field, 0);
+ gda_log_message ("cslib cannot convert type %d",
+ sfield->fmt->datatype);
+ return;
+ }
+
+ destfmt.maxlength = SYBASE_CONVBUF_SIZE;
+ destfmt.datatype = CS_CHAR_TYPE;
+ destfmt.format = CS_FMT_NULLTERM;
+ destfmt.locale = NULL;
+
+ if (cs_convert (scnc->ctx, sfield->fmt, sfield->data, &destfmt,
+ &tmpdata, &len) != CS_SUCCEED) {
+ gda_server_field_set_actual_length (field, 0);
+ return;
+ }
+
+ gda_server_field_set_varchar (field, (gchar *) & tmpdata);
+ gda_server_field_set_actual_length (field, len - 1);
+}
Index: gda-sybase-types.h
===================================================================
RCS file: /cvs/gnome/libgda/providers/gda-sybase-server/Attic/gda-sybase-types.h,v
retrieving revision 1.3
diff -u -u -r1.3 gda-sybase-types.h
--- gda-sybase-types.h 2001/07/18 23:05:42 1.3
+++ gda-sybase-types.h 2001/11/22 04:42:52
@@ -1,59 +1,59 @@
-/*
- * $Id: gda-sybase-types.h,v 1.3 2001/07/18 23:05:42 vivien Exp $
- *
- * GNOME DB sybase Provider
- * Copyright (C) 2000 Rodrigo Moya
- * Copyright (C) 2000 Stephan Heinze
- * Copyright (C) 2000 Holger Thon
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#if !defined(__gda_sybase_types_h__)
-# define __gda_sybase_types_h__
-
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-
-#include "gda-sybase.h"
-
-/*
- * Per-object specific structures
- */
-
-typedef struct _sybase_Types
-{
- gchar *name;
- CS_INT sql_type;
- GDA_ValueType gda_type;
-}
-sybase_Types;
-
-#define GDA_SYBASE_TYPE_CNT 23
-extern const sybase_Types gda_sybase_type_list[GDA_SYBASE_TYPE_CNT];
-
-const gshort sybase_get_c_type (const GDA_ValueType);
-const GDA_ValueType sybase_get_gda_type (const CS_INT);
-const CS_INT sybase_get_sql_type (const GDA_ValueType);
-const gchar *sybase_get_type_name (const CS_INT);
-
-void gda_sybase_field_set_datetime (GdaServerField *, CS_DATETIME *);
-void gda_sybase_field_set_datetime4 (GdaServerField *, CS_DATETIME4 *);
-void gda_sybase_field_set_general (GdaServerField *,
- sybase_Field *, sybase_Connection *);
-
-
-#endif
+/*
+ * $Id: gda-sybase-types.h,v 1.3 2001/07/18 23:05:42 vivien Exp $
+ *
+ * GNOME DB sybase Provider
+ * Copyright (C) 2000 Rodrigo Moya
+ * Copyright (C) 2000 Stephan Heinze
+ * Copyright (C) 2000 Holger Thon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#if !defined(__gda_sybase_types_h__)
+# define __gda_sybase_types_h__
+
+#if defined(HAVE_CONFIG_H)
+# include <config.h>
+#endif
+
+#include "gda-sybase.h"
+
+/*
+ * Per-object specific structures
+ */
+
+typedef struct _sybase_Types
+{
+ gchar *name;
+ CS_INT sql_type;
+ GDA_ValueType gda_type;
+}
+sybase_Types;
+
+#define GDA_SYBASE_TYPE_CNT 23
+extern const sybase_Types gda_sybase_type_list[GDA_SYBASE_TYPE_CNT];
+
+const gshort sybase_get_c_type (const GDA_ValueType);
+const GDA_ValueType sybase_get_gda_type (const CS_INT);
+const CS_INT sybase_get_sql_type (const GDA_ValueType);
+const gchar *sybase_get_type_name (const CS_INT);
+
+void gda_sybase_field_set_datetime (GdaServerField *, CS_DATETIME *);
+void gda_sybase_field_set_datetime4 (GdaServerField *, CS_DATETIME4 *);
+void gda_sybase_field_set_general (GdaServerField *,
+ sybase_Field *, sybase_Connection *);
+
+
+#endif
Index: gda-sybase.h
===================================================================
RCS file: /cvs/gnome/libgda/providers/gda-sybase-server/Attic/gda-sybase.h,v
retrieving revision 1.2
diff -u -u -r1.2 gda-sybase.h
--- gda-sybase.h 2000/10/19 19:01:37 1.2
+++ gda-sybase.h 2001/11/22 04:42:52
@@ -1,55 +1,55 @@
-/*
- * $Id: gda-sybase.h,v 1.2 2000/10/19 19:01:37 reinhard Exp $
- *
- * GNOME DB sybase Provider
- * Copyright (C) 2000 Rodrigo Moya
- * Copyright (C) 2000 Stephan Heinze
- * Copyright (C) 2000 Holger Thon
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#if !defined(__gda_sybase_h__)
-# define __gda_sybase_h__
-
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-
-#include <gda-server.h>
-#include <glib.h>
-#include <ctpublic.h>
-#include "gda-sybase-connection.h"
-#include "gda-sybase-command.h"
-#include "gda-sybase-error.h"
-#include "gda-sybase-recordset.h"
-#include "gda-sybase-types.h"
-
-#ifdef ENABLE_NLS
-# include <libintl.h>
-# define _(String) gettext (String)
-# define N_(String) (String)
-#else
-/* Stubs that do something close enough. */
-# define textdomain(String)
-# define gettext(String) (String)
-# define dgettext(Domain,Message) (Message)
-# define dcgettext(Domain,Message,Type) (Message)
-# define bindtextdomain(Domain,Directory)
-# define _(String) (String)
-# define N_(String) (String)
-#endif
-
-#endif
+/*
+ * $Id: gda-sybase.h,v 1.2 2000/10/19 19:01:37 reinhard Exp $
+ *
+ * GNOME DB sybase Provider
+ * Copyright (C) 2000 Rodrigo Moya
+ * Copyright (C) 2000 Stephan Heinze
+ * Copyright (C) 2000 Holger Thon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#if !defined(__gda_sybase_h__)
+# define __gda_sybase_h__
+
+#if defined(HAVE_CONFIG_H)
+# include <config.h>
+#endif
+
+#include <gda-server.h>
+#include <glib.h>
+#include <ctpublic.h>
+#include "gda-sybase-connection.h"
+#include "gda-sybase-command.h"
+#include "gda-sybase-error.h"
+#include "gda-sybase-recordset.h"
+#include "gda-sybase-types.h"
+
+#ifdef ENABLE_NLS
+# include <libintl.h>
+# define _(String) gettext (String)
+# define N_(String) (String)
+#else
+/* Stubs that do something close enough. */
+# define textdomain(String)
+# define gettext(String) (String)
+# define dgettext(Domain,Message) (Message)
+# define dcgettext(Domain,Message,Type) (Message)
+# define bindtextdomain(Domain,Directory)
+# define _(String) (String)
+# define N_(String) (String)
+#endif
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]