Lines Matching refs:S

65 static void pgsql_stmt_finish(pdo_pgsql_stmt *S, int fin_mode)  in pgsql_stmt_finish()  argument
67 pdo_pgsql_db_handle *H = S->H; in pgsql_stmt_finish()
69 if (S->is_running_unbuffered && S->result && (fin_mode & FIN_ABORT)) { in pgsql_stmt_finish()
74 S->is_running_unbuffered = false; in pgsql_stmt_finish()
77 if (S->result) { in pgsql_stmt_finish()
79 PQclear(S->result); in pgsql_stmt_finish()
80 S->result = NULL; in pgsql_stmt_finish()
83 if (S->is_running_unbuffered) { in pgsql_stmt_finish()
92 while ((S->result = PQgetResult(H->server))) { in pgsql_stmt_finish()
93 PQclear(S->result); in pgsql_stmt_finish()
94 S->result = NULL; in pgsql_stmt_finish()
96 S->is_running_unbuffered = false; in pgsql_stmt_finish()
99 if (S->stmt_name && S->is_prepared && (fin_mode & FIN_CLOSE)) { in pgsql_stmt_finish()
105 spprintf(&q, 0, "DEALLOCATE %s", S->stmt_name); in pgsql_stmt_finish()
109 res = PQclosePrepared(H->server, S->stmt_name); in pgsql_stmt_finish()
115 S->is_prepared = false; in pgsql_stmt_finish()
116 if (H->running_stmt == S) { in pgsql_stmt_finish()
124 pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data; in pgsql_stmt_dtor() local
129 pgsql_stmt_finish(S, FIN_DISCARD|(server_obj_usable ? FIN_CLOSE|FIN_ABORT : 0)); in pgsql_stmt_dtor()
131 if (S->stmt_name) { in pgsql_stmt_dtor()
132 efree(S->stmt_name); in pgsql_stmt_dtor()
133 S->stmt_name = NULL; in pgsql_stmt_dtor()
135 if (S->param_lengths) { in pgsql_stmt_dtor()
136 efree(S->param_lengths); in pgsql_stmt_dtor()
137 S->param_lengths = NULL; in pgsql_stmt_dtor()
139 if (S->param_values) { in pgsql_stmt_dtor()
140 efree(S->param_values); in pgsql_stmt_dtor()
141 S->param_values = NULL; in pgsql_stmt_dtor()
143 if (S->param_formats) { in pgsql_stmt_dtor()
144 efree(S->param_formats); in pgsql_stmt_dtor()
145 S->param_formats = NULL; in pgsql_stmt_dtor()
147 if (S->param_types) { in pgsql_stmt_dtor()
148 efree(S->param_types); in pgsql_stmt_dtor()
149 S->param_types = NULL; in pgsql_stmt_dtor()
151 if (S->query) { in pgsql_stmt_dtor()
152 zend_string_release(S->query); in pgsql_stmt_dtor()
153 S->query = NULL; in pgsql_stmt_dtor()
156 if (S->cursor_name) { in pgsql_stmt_dtor()
158 pdo_pgsql_db_handle *H = S->H; in pgsql_stmt_dtor()
162 spprintf(&q, 0, "CLOSE %s", S->cursor_name); in pgsql_stmt_dtor()
167 efree(S->cursor_name); in pgsql_stmt_dtor()
168 S->cursor_name = NULL; in pgsql_stmt_dtor()
171 if(S->cols) { in pgsql_stmt_dtor()
172 efree(S->cols); in pgsql_stmt_dtor()
173 S->cols = NULL; in pgsql_stmt_dtor()
175 efree(S); in pgsql_stmt_dtor()
182 pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data; in pgsql_stmt_execute() local
183 pdo_pgsql_db_handle *H = S->H; in pgsql_stmt_execute()
193 if (S->is_unbuffered && H->running_stmt) { in pgsql_stmt_execute()
198 pgsql_stmt_finish(S, 0); in pgsql_stmt_execute()
200 S->current_row = 0; in pgsql_stmt_execute()
202 if (S->cursor_name) { in pgsql_stmt_execute()
205 if (S->is_prepared) { in pgsql_stmt_execute()
206 spprintf(&q, 0, "CLOSE %s", S->cursor_name); in pgsql_stmt_execute()
211 …spprintf(&q, 0, "DECLARE %s SCROLL CURSOR WITH HOLD FOR %s", S->cursor_name, ZSTR_VAL(stmt->active… in pgsql_stmt_execute()
212 S->result = PQexec(H->server, q); in pgsql_stmt_execute()
216 status = PQresultStatus(S->result); in pgsql_stmt_execute()
218 pdo_pgsql_error_stmt(stmt, status, pdo_pgsql_sqlstate(S->result)); in pgsql_stmt_execute()
221 PQclear(S->result); in pgsql_stmt_execute()
224 S->is_prepared = 1; in pgsql_stmt_execute()
227 spprintf(&q, 0, "FETCH FORWARD 0 FROM %s", S->cursor_name); in pgsql_stmt_execute()
228 S->result = PQexec(H->server, q); in pgsql_stmt_execute()
230 } else if (S->stmt_name) { in pgsql_stmt_execute()
233 if (!S->is_prepared) { in pgsql_stmt_execute()
237 S->result = PQprepare(H->server, S->stmt_name, ZSTR_VAL(S->query), in pgsql_stmt_execute()
239 S->param_types); in pgsql_stmt_execute()
240 status = PQresultStatus(S->result); in pgsql_stmt_execute()
245 S->is_prepared = 1; in pgsql_stmt_execute()
246 PQclear(S->result); in pgsql_stmt_execute()
247 S->result = NULL; in pgsql_stmt_execute()
250 char *sqlstate = pdo_pgsql_sqlstate(S->result); in pgsql_stmt_execute()
261 snprintf(buf, sizeof(buf), "DEALLOCATE %s", S->stmt_name); in pgsql_stmt_execute()
264 res = PQclosePrepared(H->server, S->stmt_name); in pgsql_stmt_execute()
277 if (S->is_unbuffered) { in pgsql_stmt_execute()
278 dispatch_result = PQsendQueryPrepared(H->server, S->stmt_name, in pgsql_stmt_execute()
282 (const char**)S->param_values, in pgsql_stmt_execute()
283 S->param_lengths, in pgsql_stmt_execute()
284 S->param_formats, in pgsql_stmt_execute()
287 S->result = PQexecPrepared(H->server, S->stmt_name, in pgsql_stmt_execute()
291 (const char**)S->param_values, in pgsql_stmt_execute()
292 S->param_lengths, in pgsql_stmt_execute()
293 S->param_formats, in pgsql_stmt_execute()
298 if (S->is_unbuffered) { in pgsql_stmt_execute()
299 dispatch_result = PQsendQueryParams(H->server, ZSTR_VAL(S->query), in pgsql_stmt_execute()
301 S->param_types, in pgsql_stmt_execute()
302 (const char**)S->param_values, in pgsql_stmt_execute()
303 S->param_lengths, in pgsql_stmt_execute()
304 S->param_formats, in pgsql_stmt_execute()
307 S->result = PQexecParams(H->server, ZSTR_VAL(S->query), in pgsql_stmt_execute()
309 S->param_types, in pgsql_stmt_execute()
310 (const char**)S->param_values, in pgsql_stmt_execute()
311 S->param_lengths, in pgsql_stmt_execute()
312 S->param_formats, in pgsql_stmt_execute()
317 if (S->is_unbuffered) { in pgsql_stmt_execute()
320 S->result = PQexec(H->server, ZSTR_VAL(stmt->active_query_string)); in pgsql_stmt_execute()
324 H->running_stmt = S; in pgsql_stmt_execute()
326 if (S->is_unbuffered) { in pgsql_stmt_execute()
332 S->is_running_unbuffered = true; in pgsql_stmt_execute()
337 S->result = PQgetResult(S->H->server); in pgsql_stmt_execute()
340 status = PQresultStatus(S->result); in pgsql_stmt_execute()
343 pdo_pgsql_error_stmt(stmt, status, pdo_pgsql_sqlstate(S->result)); in pgsql_stmt_execute()
347 stmt->column_count = (int) PQnfields(S->result); in pgsql_stmt_execute()
348 if (S->cols == NULL) { in pgsql_stmt_execute()
349 S->cols = ecalloc(stmt->column_count, sizeof(pdo_pgsql_column)); in pgsql_stmt_execute()
353 stmt->row_count = ZEND_ATOL(PQcmdTuples(S->result)); in pgsql_stmt_execute()
354 H->pgoid = PQoidValue(S->result); in pgsql_stmt_execute()
356 stmt->row_count = (zend_long)PQntuples(S->result); in pgsql_stmt_execute()
369 pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data; in pgsql_stmt_param_hook() local
419 if (!S->param_values) { in pgsql_stmt_param_hook()
420 S->param_values = ecalloc( in pgsql_stmt_param_hook()
423 S->param_lengths = ecalloc( in pgsql_stmt_param_hook()
426 S->param_formats = ecalloc( in pgsql_stmt_param_hook()
429 S->param_types = ecalloc( in pgsql_stmt_param_hook()
463 S->param_values[param->paramno] = (char*)&P->oid; in pgsql_stmt_param_hook()
464 S->param_lengths[param->paramno] = sizeof(P->oid); in pgsql_stmt_param_hook()
465 S->param_formats[param->paramno] = 1; in pgsql_stmt_param_hook()
466 S->param_types[param->paramno] = OIDOID; in pgsql_stmt_param_hook()
485 S->param_values[param->paramno] = NULL; in pgsql_stmt_param_hook()
486 S->param_lengths[param->paramno] = 0; in pgsql_stmt_param_hook()
488 S->param_values[param->paramno] = Z_TYPE_P(parameter) == IS_TRUE ? "t" : "f"; in pgsql_stmt_param_hook()
489 S->param_lengths[param->paramno] = 1; in pgsql_stmt_param_hook()
490 S->param_formats[param->paramno] = 0; in pgsql_stmt_param_hook()
493 S->param_values[param->paramno] = Z_STRVAL_P(parameter); in pgsql_stmt_param_hook()
494 S->param_lengths[param->paramno] = Z_STRLEN_P(parameter); in pgsql_stmt_param_hook()
495 S->param_formats[param->paramno] = 0; in pgsql_stmt_param_hook()
499 S->param_types[param->paramno] = 0; in pgsql_stmt_param_hook()
500 S->param_formats[param->paramno] = 1; in pgsql_stmt_param_hook()
502 S->param_types[param->paramno] = 0; in pgsql_stmt_param_hook()
523 pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data; in pgsql_stmt_fetch() local
525 if (S->cursor_name) { in pgsql_stmt_fetch()
541 if(S->result) { in pgsql_stmt_fetch()
542 PQclear(S->result); in pgsql_stmt_fetch()
543 S->result = NULL; in pgsql_stmt_fetch()
546 spprintf(&q, 0, "FETCH %s FROM %s", ori_str, S->cursor_name); in pgsql_stmt_fetch()
548 S->result = PQexec(S->H->server, q); in pgsql_stmt_fetch()
550 status = PQresultStatus(S->result); in pgsql_stmt_fetch()
553 pdo_pgsql_error_stmt(stmt, status, pdo_pgsql_sqlstate(S->result)); in pgsql_stmt_fetch()
557 if (PQntuples(S->result)) { in pgsql_stmt_fetch()
558 S->current_row = 1; in pgsql_stmt_fetch()
564 if (S->is_running_unbuffered && S->current_row >= stmt->row_count) { in pgsql_stmt_fetch()
570 if(S->result) { in pgsql_stmt_fetch()
571 PQclear(S->result); in pgsql_stmt_fetch()
572 S->result = NULL; in pgsql_stmt_fetch()
575 S->result = PQgetResult(S->H->server); in pgsql_stmt_fetch()
576 status = PQresultStatus(S->result); in pgsql_stmt_fetch()
579 pdo_pgsql_error_stmt(stmt, status, pdo_pgsql_sqlstate(S->result)); in pgsql_stmt_fetch()
583 stmt->row_count = (zend_long)PQntuples(S->result); in pgsql_stmt_fetch()
584 S->current_row = 0; in pgsql_stmt_fetch()
587 S->is_running_unbuffered = false; in pgsql_stmt_fetch()
589 pgsql_stmt_finish(S, 0); in pgsql_stmt_fetch()
592 if (S->current_row < stmt->row_count) { in pgsql_stmt_fetch()
593 S->current_row++; in pgsql_stmt_fetch()
603 pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data; in pgsql_stmt_describe() local
607 if (!S->result) { in pgsql_stmt_describe()
611 str = PQfname(S->result, colno); in pgsql_stmt_describe()
613 cols[colno].maxlen = PQfsize(S->result, colno); in pgsql_stmt_describe()
614 cols[colno].precision = PQfmod(S->result, colno); in pgsql_stmt_describe()
615 S->cols[colno].pgsql_type = PQftype(S->result, colno); in pgsql_stmt_describe()
622 pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data; in pgsql_stmt_get_col() local
623 if (!S->result) { in pgsql_stmt_get_col()
628 if (PQgetisnull(S->result, S->current_row - 1, colno)) { /* Check if we got NULL */ in pgsql_stmt_get_col()
631 char *ptr = PQgetvalue(S->result, S->current_row - 1, colno); in pgsql_stmt_get_col()
632 size_t len = PQgetlength(S->result, S->current_row - 1, colno); in pgsql_stmt_get_col()
634 switch (S->cols[colno].pgsql_type) { in pgsql_stmt_get_col()
664 int loid = lo_open(S->H->server, oid, INV_READ); in pgsql_stmt_get_col()
735 pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data; in pgsql_stmt_get_column_meta() local
742 if (!S->result) { in pgsql_stmt_get_column_meta()
751 add_assoc_long(return_value, "pgsql:oid", S->cols[colno].pgsql_type); in pgsql_stmt_get_column_meta()
753 table_oid = PQftable(S->result, colno); in pgsql_stmt_get_column_meta()
755 table_name = pdo_pgsql_translate_oid_to_table(table_oid, S->H->server); in pgsql_stmt_get_column_meta()
761 switch (S->cols[colno].pgsql_type) { in pgsql_stmt_get_column_meta()
797 spprintf(&q, 0, "SELECT TYPNAME FROM PG_TYPE WHERE OID=%u", S->cols[colno].pgsql_type); in pgsql_stmt_get_column_meta()
798 res = PQexec(S->H->server, q); in pgsql_stmt_get_column_meta()
808 switch (S->cols[colno].pgsql_type) { in pgsql_stmt_get_column_meta()
836 pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data; in pgsql_stmt_get_attr() local
842 ZVAL_LONG(val, PQresultMemorySize(S->result)); in pgsql_stmt_get_attr()
845 spprintf(&tmp, 0, "statement '%s' has not been executed yet", S->stmt_name); in pgsql_stmt_get_attr()
856 (void)S; in pgsql_stmt_get_attr()