1 /*
2 * Copyright (C) 2008 - 2012 Vivien Malerba <malerba@gnome-db.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include <string.h>
21 #include <glib/gi18n-lib.h>
22 #include "gda-firebird-pstmt.h"
23
24 static void gda_firebird_pstmt_class_init (GdaFirebirdPStmtClass *klass);
25 static void gda_firebird_pstmt_init (GdaFirebirdPStmt *pstmt, GdaFirebirdPStmtClass *klass);
26 static void gda_firebird_pstmt_finalize (GObject *object);
27
28 static GObjectClass *parent_class = NULL;
29
30 /**
31 * gda_firebird_pstmt_get_type
32 *
33 * Returns: the #GType of GdaFirebirdPStmt.
34 */
35 GType
gda_firebird_pstmt_get_type(void)36 gda_firebird_pstmt_get_type (void)
37 {
38 static GType type = 0;
39
40 if (G_UNLIKELY (type == 0)) {
41 static GMutex registering;
42 static const GTypeInfo info = {
43 sizeof (GdaFirebirdPStmtClass),
44 (GBaseInitFunc) NULL,
45 (GBaseFinalizeFunc) NULL,
46 (GClassInitFunc) gda_firebird_pstmt_class_init,
47 NULL,
48 NULL,
49 sizeof (GdaFirebirdPStmt),
50 0,
51 (GInstanceInitFunc) gda_firebird_pstmt_init,
52 0
53 };
54
55 g_mutex_lock (®istering);
56 if (type == 0) {
57 #ifdef FIREBIRD_EMBED
58 type = g_type_register_static (GDA_TYPE_PSTMT, "GdaFirebirdPStmtEmbed", &info, 0);
59 #else
60 type = g_type_register_static (GDA_TYPE_PSTMT, "GdaFirebirdPStmt", &info, 0);
61 #endif
62 }
63 g_mutex_unlock (®istering);
64 }
65 return type;
66 }
67
68 static void
gda_firebird_pstmt_class_init(GdaFirebirdPStmtClass * klass)69 gda_firebird_pstmt_class_init (GdaFirebirdPStmtClass *klass)
70 {
71 //WHERE_AM_I;
72 GObjectClass *object_class = G_OBJECT_CLASS (klass);
73 parent_class = g_type_class_peek_parent (klass);
74
75 /* virtual functions */
76 object_class->finalize = gda_firebird_pstmt_finalize;
77 }
78
79 static void
gda_firebird_pstmt_init(GdaFirebirdPStmt * pstmt,GdaFirebirdPStmtClass * klass)80 gda_firebird_pstmt_init (GdaFirebirdPStmt *pstmt, GdaFirebirdPStmtClass *klass)
81 {
82 g_return_if_fail (GDA_IS_PSTMT (pstmt));
83 //WHERE_AM_I;
84 /* initialize specific parts of @pstmt */
85 if (pstmt->stmt_h != 0){
86 g_print("\t\tEXISTING PSTMT\n");
87 if (!isc_dsql_free_statement(pstmt->status, &(pstmt->stmt_h), DSQL_close)){
88 isc_print_status(pstmt->status);
89 }
90
91 pstmt->stmt_h = 0;
92 }
93 //else
94 //g_print("\t\tNO STATEMENT\n");
95
96 if (pstmt->sqlda != NULL){
97 //g_print("\t\tEXISTING SQLDA\n");
98
99 g_free(pstmt->sqlda);
100 pstmt->sqlda = NULL;
101 }
102
103 if (pstmt->input_sqlda != NULL){
104 //g_print("\t\tEXISTING SQLDA\n");
105 g_free(pstmt->input_sqlda);
106 pstmt->input_sqlda = NULL;
107 }
108 //else
109 //g_print("\t\tNO SQLDA\n");
110 }
111
112 static void
gda_firebird_pstmt_finalize(GObject * object)113 gda_firebird_pstmt_finalize (GObject *object)
114 {
115 //WHERE_AM_I;
116
117 GdaFirebirdPStmt *pstmt = (GdaFirebirdPStmt *) object;
118 g_return_if_fail (GDA_IS_PSTMT (pstmt));
119
120 /* free memory */
121 //TO_IMPLEMENT; /* free some specific parts of @pstmt */
122 if (pstmt->stmt_h != 0){
123 g_print("\t\tCLOSE STATEMENT\n");
124 if (!isc_dsql_free_statement(pstmt->status, &(pstmt->stmt_h), DSQL_close)){
125 isc_print_status(pstmt->status);
126 }
127 }
128 else{
129 //g_print("\t\tNO STATEMENT TO CLOSE\n");
130 }
131 //g_free(pstmt->sqlda);
132 //pstmt->sqlda = NULL;
133 pstmt->stmt_h = 0;
134
135 if (pstmt->sqlda != NULL){
136 g_print("\t\tEXISTING SQLDA\n");
137 g_free(pstmt->sqlda);
138 pstmt->sqlda = NULL;
139 }
140
141 if (pstmt->input_sqlda != NULL){
142 g_print("\t\tEXISTING SQLDA\n");
143 g_free(pstmt->input_sqlda);
144 pstmt->input_sqlda = NULL;
145 }
146
147 /* chain to parent class */
148 parent_class->finalize (object);
149 }
150