Skip to content

Commit 4f2edac

Browse files
committed
Move ibase_query, ibase_array to php_ibase_includes.h; remove ibase_result, ibase_statement structs
1 parent 77c0e41 commit 4f2edac

2 files changed

Lines changed: 47 additions & 103 deletions

File tree

ibase_query.c

Lines changed: 3 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -48,71 +48,13 @@
4848
#define FETCH_ROW 1
4949
#define FETCH_ARRAY 2
5050

51-
typedef struct {
52-
ISC_ARRAY_DESC ar_desc;
53-
ISC_LONG ar_size; /* size of entire array in bytes */
54-
unsigned short el_type, el_size;
55-
} ibase_array;
56-
57-
typedef struct {
58-
ibase_db_link* link;
59-
isc_stmt_handle stmt;
60-
} ibase_statement;
61-
62-
typedef struct {
63-
ibase_db_link *link;
64-
ibase_trans *trans;
65-
isc_stmt_handle stmt;
66-
zend_resource* stmt_res;
67-
unsigned short type;
68-
unsigned char has_more_rows, statement_type;
69-
XSQLDA *out_sqlda;
70-
ibase_array out_array[1]; /* last member */
71-
} ibase_result;
72-
73-
typedef struct _ib_query {
74-
ibase_db_link *link;
75-
ibase_trans *trans;
76-
zend_resource *result_res;
77-
isc_stmt_handle stmt;
78-
zend_resource *stmt_res;
79-
XSQLDA *in_sqlda, *out_sqlda;
80-
ibase_array *in_array, *out_array;
81-
unsigned short in_array_cnt, out_array_cnt;
82-
unsigned short dialect;
83-
char statement_type;
84-
char *query;
85-
zend_resource *trans_res;
86-
} ibase_query;
87-
8851
typedef struct {
8952
unsigned short vary_length;
9053
char vary_string[1];
9154
} IBVARY;
9255

93-
/* sql variables union
94-
* used for convert and binding input variables
95-
*/
96-
typedef struct {
97-
union {
98-
// Boolean data type exists since FB 3.0
99-
#ifdef SQL_BOOLEAN
100-
FB_BOOLEAN bval;
101-
#endif
102-
short sval;
103-
float fval;
104-
ISC_LONG lval;
105-
ISC_QUAD qval;
106-
ISC_TIMESTAMP tsval;
107-
ISC_DATE dtval;
108-
ISC_TIME tmval;
109-
} val;
110-
short sqlind;
111-
} BIND_BUF;
112-
113-
static int le_statement, le_result, le_query;
114-
115-
#define LE_RESULT "Firebird/InterBase result"
56+
static int le_query;
57+
11658
#define LE_QUERY "Firebird/InterBase query"
11759

11860
static void _php_ibase_free_xsqlda(XSQLDA *sqlda) /* {{{ */
@@ -135,45 +77,6 @@ static void _php_ibase_free_xsqlda(XSQLDA *sqlda) /* {{{ */
13577
}
13678
/* }}} */
13779

138-
static void _php_ibase_free_statement(zend_resource* rsrc) /* {{{ */
139-
{
140-
ibase_statement* ib_stmt = (ibase_statement*)rsrc->ptr;
141-
142-
IBDEBUG("Freeing statement by dtor...");
143-
if (ib_stmt) {
144-
if (ib_stmt->stmt) {
145-
static char info[] = { isc_info_base_level, isc_info_end };
146-
char res_buf[8];
147-
IBDEBUG("Dropping statement handle (free_stmt_handle)...");
148-
/* Only free statement if db-connection is still open */
149-
if (SUCCESS == isc_database_info(IB_STATUS, &ib_stmt->link->handle,
150-
sizeof(info), info, sizeof(res_buf), res_buf)) {
151-
if (isc_dsql_free_statement(IB_STATUS, &ib_stmt->stmt, DSQL_drop)) {
152-
_php_ibase_error();
153-
}
154-
}
155-
}
156-
efree(ib_stmt);
157-
}
158-
}
159-
/* }}} */
160-
161-
static void _php_ibase_free_result(zend_resource *rsrc) /* {{{ */
162-
{
163-
ibase_result *ib_result = (ibase_result *) rsrc->ptr;
164-
165-
IBDEBUG("Freeing result by dtor...");
166-
if (ib_result) {
167-
_php_ibase_free_xsqlda(ib_result->out_sqlda);
168-
if (ib_result->stmt_res != NULL) {
169-
zend_list_delete(ib_result->stmt_res);
170-
ib_result->stmt_res = NULL;
171-
}
172-
efree(ib_result);
173-
}
174-
}
175-
/* }}} */
176-
17780
static void _php_ibase_free_query(ibase_query *ib_query) /* {{{ */
17881
{
17982
IBDEBUG("Freeing query...");
@@ -218,10 +121,7 @@ static void php_ibase_free_query_rsrc(zend_resource *rsrc) /* {{{ */
218121

219122
void php_ibase_query_minit(INIT_FUNC_ARGS) /* {{{ */
220123
{
221-
le_statement = zend_register_list_destructors_ex(_php_ibase_free_statement, NULL,
222-
"interbase statement", module_number);
223-
le_result = zend_register_list_destructors_ex(_php_ibase_free_result, NULL,
224-
"interbase result", module_number);
124+
(void)type;
225125
le_query = zend_register_list_destructors_ex(php_ibase_free_query_rsrc, NULL,
226126
"interbase query", module_number);
227127
}

php_ibase_includes.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,50 @@ typedef struct event {
117117
enum event_state { NEW, ACTIVE, DEAD } state;
118118
} ibase_event;
119119

120+
/* sql variables union
121+
* used for convert and binding input variables
122+
*/
123+
typedef struct {
124+
union {
125+
// Boolean data type exists since FB 3.0
126+
#ifdef SQL_BOOLEAN
127+
FB_BOOLEAN bval;
128+
#endif
129+
short sval;
130+
float fval;
131+
ISC_LONG lval;
132+
ISC_QUAD qval;
133+
ISC_TIMESTAMP tsval;
134+
ISC_DATE dtval;
135+
ISC_TIME tmval;
136+
} val;
137+
short nullind;
138+
} BIND_BUF;
139+
140+
typedef struct {
141+
ISC_ARRAY_DESC ar_desc;
142+
ISC_LONG ar_size; /* size of entire array in bytes */
143+
unsigned short el_type, el_size;
144+
} ibase_array;
145+
146+
typedef struct _ib_query {
147+
ibase_db_link *link;
148+
ibase_trans *trans;
149+
zend_resource *res;
150+
isc_stmt_handle stmt;
151+
XSQLDA *in_sqlda, *out_sqlda;
152+
ibase_array *in_array, *out_array;
153+
unsigned short type, has_more_rows, is_open;
154+
unsigned short in_array_cnt, out_array_cnt;
155+
unsigned short dialect;
156+
char *query;
157+
ISC_UCHAR statement_type;
158+
BIND_BUF *bind_buf;
159+
ISC_SHORT *in_nullind, *out_nullind;
160+
ISC_USHORT in_fields_count, out_fields_count;
161+
HashTable *ht_aliases, *ht_ind; // Precomputed for ibase_fetch_*()
162+
} ibase_query;
163+
120164
enum php_interbase_option {
121165
PHP_IBASE_DEFAULT = 0,
122166
PHP_IBASE_CREATE = 0,

0 commit comments

Comments
 (0)