/** * _gda_jdbc_make_error * * warning: STEALS @sql_state and @error. * Create a new #GdaConnectionEvent object and "adds" it to @cnc * * Returns: a new GdaConnectionEvent which must not be unrefed() */ GdaConnectionEvent * _gda_jdbc_make_error (GdaConnection *cnc, gint error_code, gchar *sql_state, GError *error) { GdaConnectionEvent *error_ev; GdaConnectionEventCode gda_code = GDA_CONNECTION_EVENT_CODE_UNKNOWN; GdaTransactionStatus *trans; error_ev = GDA_CONNECTION_EVENT (g_object_new (GDA_TYPE_CONNECTION_EVENT, "type", (gint) GDA_CONNECTION_EVENT_ERROR, NULL)); if (error) { gda_connection_event_set_description (error_ev, error->message ? error->message : _("No detail")); g_error_free (error); } gda_connection_event_set_sqlstate (error_ev, sql_state); g_free (sql_state); gda_connection_event_set_code (error_ev, error_code); gda_connection_event_set_gda_code (error_ev, gda_code); gda_connection_event_set_source (error_ev, "gda-jdbc"); gda_connection_add_event (cnc, error_ev); /* change the transaction status if there is a problem */ trans = gda_connection_get_transaction_status (cnc); if (trans) { /* if ((PQtransactionStatus (pconn) == PQTRANS_INERROR) && (trans->state != GDA_TRANSACTION_STATUS_STATE_FAILED)) gda_connection_internal_change_transaction_state (cnc, GDA_TRANSACTION_STATUS_STATE_FAILED); */ } return error_ev; }
/** * base_tool_command_result_new: * @type: a #ToolCommandResultType * * Returns: (transfer full): a new #ToolCommandResult */ ToolCommandResult * base_tool_command_result_new (GdaConnection *cnc, ToolCommandResultType type) { ToolCommandResult *res; res = g_new0 (ToolCommandResult, 1); res->type = type; if (cnc) { res->was_in_transaction_before_exec = gda_connection_get_transaction_status (cnc) ? TRUE : FALSE; res->cnc = g_object_ref (cnc); } return res; }
/** * base_tool_command_result_free: * @res: (allow-none): a #ToolCommandResult, or %NULL * * Frees any resource used by @res */ void base_tool_command_result_free (ToolCommandResult *res) { if (!res) return; switch (res->type) { case BASE_TOOL_COMMAND_RESULT_DATA_MODEL: if (res->u.model) g_object_unref (res->u.model); if (! res->was_in_transaction_before_exec && res->cnc && gda_connection_get_transaction_status (res->cnc)) gda_connection_rollback_transaction (res->cnc, NULL, NULL); break; case BASE_TOOL_COMMAND_RESULT_SET: if (res->u.set) g_object_unref (res->u.set); break; case BASE_TOOL_COMMAND_RESULT_TREE: if (res->u.tree) g_object_unref (res->u.tree); break; case BASE_TOOL_COMMAND_RESULT_TXT: case BASE_TOOL_COMMAND_RESULT_TXT_STDOUT: if (res->u.txt) g_string_free (res->u.txt, TRUE); break; case BASE_TOOL_COMMAND_RESULT_MULTIPLE: { GSList *list; for (list = res->u.multiple_results; list; list = list->next) base_tool_command_result_free ((ToolCommandResult *) list->data); g_slist_free (res->u.multiple_results); break; } case BASE_TOOL_COMMAND_RESULT_HELP: if (res->u.xml_node) xmlFreeNode (res->u.xml_node); break; case BASE_TOOL_COMMAND_RESULT_EXIT: case BASE_TOOL_COMMAND_RESULT_EMPTY: break; default: g_assert_not_reached (); break; } if (res->cnc) g_object_unref (res->cnc); g_free (res); }
gboolean midgard_cr_core_transaction_get_status (MidgardCRCoreTransaction *self) { _ASSERT_T_MGD (self); GdaConnection *cnc = _T_CNC (self); if (!cnc) return FALSE; GdaTransactionStatus *status = gda_connection_get_transaction_status(cnc); if (status->state == 0) return TRUE; return FALSE; }
/* * Adds a HASH to the message using @hash_key, or adds "NOHASH" if @hash_key is %NULL * * If there is an error, then gda_connection_add_event_string() is called * * @out_status_chr, if NOT NULL will contain the 1st char of the <status> node's contents */ xmlDocPtr _gda_web_send_message_to_frontend (GdaConnection *cnc, WebConnectionData *cdata, WebMessageType msgtype, const gchar *message, const gchar *hash_key, gchar *out_status_chr) { SoupMessage *msg; guint status; gchar *h_message; gchar *real_url; static gint counter = 0; if (out_status_chr) *out_status_chr = 0; /* handle the need to run the worker to get an initial sessionID */ g_rec_mutex_lock (& (cdata->mutex)); cdata->worker_needed = TRUE; if (!cdata->worker_running && !cdata->session_id) { g_rec_mutex_unlock (& (cdata->mutex)); start_worker (cnc, cdata); g_rec_mutex_lock (& (cdata->mutex)); if (! cdata->worker_running) { gda_connection_add_event_string (cnc, _("Could not run PHP script on the server")); cdata->worker_needed = FALSE; g_rec_mutex_unlock (& (cdata->mutex)); return NULL; } } /* prepare new message */ g_assert (cdata->session_id); real_url = g_strdup_printf ("%s?%s&c=%d", cdata->front_url, cdata->session_id, counter++); g_rec_mutex_unlock (& (cdata->mutex)); msg = soup_message_new ("POST", real_url); if (!msg) { gda_connection_add_event_string (cnc, _("Invalid HOST/SCRIPT '%s'"), real_url); g_free (real_url); return NULL; } g_free (real_url); /* check context */ g_rec_mutex_lock (& (cdata->mutex)); if (gda_connection_get_transaction_status (cnc) && (!cdata->worker_running || ((msgtype == MESSAGE_EXEC) && (cdata->last_exec_counter != cdata->worker_counter)))) { /* update cdata->last_exec_counter so next statement can be run */ cdata->last_exec_counter = cdata->worker_counter; gda_connection_add_event_string (cnc, _("The transaction has been automatically rolled back")); g_object_unref (msg); gda_connection_internal_reset_transaction_status (cnc); g_rec_mutex_unlock (& (cdata->mutex)); return NULL; } if (! cdata->worker_running) { g_rec_mutex_unlock (& (cdata->mutex)); start_worker (cnc, cdata); g_rec_mutex_lock (& (cdata->mutex)); if (! cdata->worker_running) { gda_connection_add_event_string (cnc, _("Could not run PHP script on the server")); g_object_unref (msg); g_rec_mutex_unlock (& (cdata->mutex)); return NULL; } } g_rec_mutex_unlock (& (cdata->mutex)); /* finalize and send message */ if (hash_key) { gchar *md5str; md5str = g_compute_hmac_for_string (G_CHECKSUM_MD5, hash_key, strlen (hash_key), message, -1); GString *string; string = g_string_new (md5str); g_free (md5str); g_string_append_c (string, '\n'); g_string_append (string, message); h_message = g_string_free (string, FALSE); } else h_message = g_strdup_printf ("NOHASH\n%s", message); #ifdef DEBUG_WEB_PROV g_print ("=== START of request ===\n%s\n=== END of request ===\n", h_message); #endif soup_message_set_request (msg, "text/plain", SOUP_MEMORY_COPY, h_message, strlen (h_message)); g_free (h_message); g_object_set (G_OBJECT (cdata->front_session), SOUP_SESSION_TIMEOUT, 20, NULL); status = soup_session_send_message (cdata->front_session, msg); g_rec_mutex_lock (& (cdata->mutex)); cdata->worker_needed = FALSE; g_rec_mutex_unlock (& (cdata->mutex)); if (!SOUP_STATUS_IS_SUCCESSFUL (status)) { gda_connection_add_event_string (cnc, msg->reason_phrase); g_object_unref (msg); return NULL; } xmlDocPtr doc; guint counter_id; doc = _gda_web_decode_response (cnc, cdata, msg->response_body, out_status_chr, &counter_id); g_object_unref (msg); g_rec_mutex_lock (& (cdata->mutex)); if (msgtype == MESSAGE_EXEC) cdata->last_exec_counter = counter_id; g_rec_mutex_unlock (& (cdata->mutex)); return doc; }