1 /*
2 * Copyright (C) 2008 Murray Cumming <murrayc@murrayc.com>
3 * Copyright (C) 2008 - 2011 Vivien Malerba <malerba@gnome-db.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #include <glib/gi18n-lib.h>
22 #include "gda-mysql-util.h"
23
24 /*
25 * Create a new #GdaConnectionEvent object and "adds" it to @cnc
26 *
27 * Returns: a new GdaConnectionEvent which must not be unrefed()
28 */
29 GdaConnectionEvent *
_gda_mysql_make_error(GdaConnection * cnc,MYSQL * mysql,MYSQL_STMT * mysql_stmt,GError ** error)30 _gda_mysql_make_error (GdaConnection *cnc,
31 MYSQL *mysql,
32 MYSQL_STMT *mysql_stmt,
33 GError **error)
34 {
35 GdaConnectionEvent *event_error =
36 gda_connection_point_available_event (cnc, GDA_CONNECTION_EVENT_ERROR);
37 if (mysql) {
38 gda_connection_event_set_sqlstate
39 (event_error, mysql_sqlstate (mysql));
40 gda_connection_event_set_description
41 (event_error, mysql_error (mysql));
42 gda_connection_event_set_code
43 (event_error, (glong) mysql_errno (mysql));
44 g_set_error (error, GDA_SERVER_PROVIDER_ERROR, GDA_SERVER_PROVIDER_STATEMENT_EXEC_ERROR,
45 "%s", mysql_error (mysql));
46
47 //g_print ("%s: %s\n", __func__, mysql_error (mysql));
48
49 } else if (mysql_stmt) {
50 gda_connection_event_set_sqlstate
51 (event_error, mysql_stmt_sqlstate (mysql_stmt));
52 gda_connection_event_set_description
53 (event_error, mysql_stmt_error (mysql_stmt));
54 gda_connection_event_set_code
55 (event_error, (glong) mysql_stmt_errno (mysql_stmt));
56 g_set_error (error, GDA_SERVER_PROVIDER_ERROR, GDA_SERVER_PROVIDER_STATEMENT_EXEC_ERROR,
57 "%s", mysql_stmt_error (mysql_stmt));
58
59 //g_print ("%s : %s\n", __func__, mysql_stmt_error (mysql_stmt));
60
61 } else {
62 gda_connection_event_set_sqlstate
63 (event_error, _("Unknown"));
64 gda_connection_event_set_description
65 (event_error, _("No description"));
66 gda_connection_event_set_code
67 (event_error, GDA_CONNECTION_EVENT_CODE_UNKNOWN);
68 g_set_error (error, GDA_SERVER_PROVIDER_ERROR, GDA_SERVER_PROVIDER_STATEMENT_EXEC_ERROR,
69 "%s", _("No detail"));
70 }
71 gda_connection_event_set_source (event_error, "gda-mysql");
72
73 gda_connection_add_event (cnc, event_error);
74
75 return event_error;
76 }
77