1 /*
2 * Copyright (C) 2008 - 2011 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-oracle-pstmt.h"
23 #include "gda-oracle-util.h"
24
25 static void gda_oracle_pstmt_class_init (GdaOraclePStmtClass *klass);
26 static void gda_oracle_pstmt_init (GdaOraclePStmt *pstmt, GdaOraclePStmtClass *klass);
27 static void gda_oracle_pstmt_finalize (GObject *object);
28
29 static GObjectClass *parent_class = NULL;
30
31 /**
32 * gda_oracle_pstmt_get_type
33 *
34 * Returns: the #GType of GdaOraclePStmt.
35 */
36 GType
gda_oracle_pstmt_get_type(void)37 gda_oracle_pstmt_get_type (void)
38 {
39 static GType type = 0;
40
41 if (G_UNLIKELY (type == 0)) {
42 static GMutex registering;
43 static const GTypeInfo info = {
44 sizeof (GdaOraclePStmtClass),
45 (GBaseInitFunc) NULL,
46 (GBaseFinalizeFunc) NULL,
47 (GClassInitFunc) gda_oracle_pstmt_class_init,
48 NULL,
49 NULL,
50 sizeof (GdaOraclePStmt),
51 0,
52 (GInstanceInitFunc) gda_oracle_pstmt_init,
53 NULL
54 };
55
56 g_mutex_lock (®istering);
57 if (type == 0)
58 type = g_type_register_static (GDA_TYPE_PSTMT, "GdaOraclePStmt", &info, 0);
59 g_mutex_unlock (®istering);
60 }
61 return type;
62 }
63
64 static void
gda_oracle_pstmt_class_init(GdaOraclePStmtClass * klass)65 gda_oracle_pstmt_class_init (GdaOraclePStmtClass *klass)
66 {
67 GObjectClass *object_class = G_OBJECT_CLASS (klass);
68 parent_class = g_type_class_peek_parent (klass);
69
70 /* virtual functions */
71 object_class->finalize = gda_oracle_pstmt_finalize;
72 }
73
74 static void
gda_oracle_pstmt_init(GdaOraclePStmt * pstmt,GdaOraclePStmtClass * klass)75 gda_oracle_pstmt_init (GdaOraclePStmt *pstmt, GdaOraclePStmtClass *klass)
76 {
77 g_return_if_fail (GDA_IS_PSTMT (pstmt));
78
79 /* initialize specific parts of @pstmt */
80 pstmt->hstmt = NULL;
81 pstmt->ora_values = NULL;
82 }
83
84 static void
gda_oracle_pstmt_finalize(GObject * object)85 gda_oracle_pstmt_finalize (GObject *object)
86 {
87 GdaOraclePStmt *pstmt = (GdaOraclePStmt *) object;
88
89 g_return_if_fail (GDA_IS_PSTMT (pstmt));
90
91 /* free memory */
92 OCIStmtRelease ((dvoid *) pstmt->hstmt, NULL, NULL, 0, OCI_STRLS_CACHE_DELETE);
93 if (pstmt->ora_values) {
94 g_list_foreach (pstmt->ora_values, (GFunc) _gda_oracle_value_free, NULL);
95 g_list_free (pstmt->ora_values);
96 }
97
98 /* chain to parent class */
99 parent_class->finalize (object);
100 }
101
102 GdaOraclePStmt *
gda_oracle_pstmt_new(OCIStmt * hstmt)103 gda_oracle_pstmt_new (OCIStmt *hstmt)
104 {
105 GdaOraclePStmt *pstmt;
106
107 pstmt = (GdaOraclePStmt *) g_object_new (GDA_TYPE_ORACLE_PSTMT, NULL);
108 pstmt->hstmt = hstmt;
109
110 return pstmt;
111
112 }
113