📄 ifx.ec
字号:
RETURN_FALSE; } /* initialize result data structure */ Ifx_Result->rowid = 0; strcpy(Ifx_Result->connecid, ifx); strcpy(Ifx_Result->cursorid, cursorid); strcpy(Ifx_Result->descrpid, descrpid); strcpy(Ifx_Result->i_descrpid, i_descrpid); strcpy(Ifx_Result->statemid, statemid); Ifx_Result->numcols = 0; Ifx_Result->numicols = 0; for (i = 0; i < MAX_RESID; ++i) { Ifx_Result->res_id[i] = -1; } if (!php_intifx_alloc_ibind(Ifx_Result, num_params TSRMLS_CC)) { char *ifx_err = ifx_error(ifx); IFXG(sv_sqlcode) = SQLCODE; EXEC SQL free :statemid; efree(Ifx_Result); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Allocate i_desciptor <%s> fails (%s)", i_descrpid, ifx_err); efree(ifx_err); RETURN_FALSE; } desc_count = php_intifx_count_descriptors(statemid TSRMLS_CC); if (desc_count == 0) { desc_count = 1; } EXEC SQL ALLOCATE DESCRIPTOR :descrpid WITH MAX :desc_count; if (ifx_check() < 0) { char *ifx_err = ifx_error(ifx); IFXG(sv_sqlcode) = SQLCODE; php_error_docref(NULL TSRMLS_CC, E_WARNING, "Allocate desciptor <%s> fails (%s)", descrpid, ifx_err); EXEC SQL free :statemid; efree(ifx_err); RETURN_FALSE; } EXEC SQL DESCRIBE :statemid USING SQL DESCRIPTOR :descrpid; if (ifx_check() < 0) { char *ifx_err = ifx_error(ifx); IFXG(sv_sqlcode) = SQLCODE; php_error_docref(NULL TSRMLS_CC, E_WARNING, "Describe fails (%s)", ifx_err); EXEC SQL DEALLOCATE DESCRIPTOR :descrpid; EXEC SQL free :statemid; efree(ifx_err); RETURN_FALSE; } query_type = sqlca.sqlcode; cursoryproc = 0; if (query_type == SQ_EXECPROC) { EXEC SQL GET DESCRIPTOR :descrpid :i = COUNT; if (i > 0) { cursoryproc = 1; } } Ifx_Result->iscursory = -1; /* prevent ifx_do */ Ifx_Result->paramquery=0; if ((query_type != 0) && (!cursoryproc)) { /* NO RESULT SET */ /* ## ## NONSELECT-STATEMENT ## */ zval **pblobidarr, **tmp; /* We don't need this descriptor anymore, NONSELECT-STATEMENT */ EXEC SQL DEALLOCATE DESCRIPTOR :descrpid; Ifx_Result->iscursory = 0; if (argc > 3) { WRONG_PARAM_COUNT; } if (argc == 3) { Ifx_Result->paramquery = 1; if (Ifx_Result->numicols <= 0) { IFXG(sv_sqlcode) = SQLCODE; EXEC SQL free :statemid; efree(Ifx_Result); php_error_docref(NULL TSRMLS_CC, E_WARNING, "No placeholders (?) in Statement, but blob array param supplied"); RETURN_FALSE; } if (zend_get_parameters_ex(3, &dummy, &dummy, &pblobidarr) == FAILURE) { IFXG(sv_sqlcode) = SQLCODE; EXEC SQL DEALLOCATE DESCRIPTOR :i_descrpid; EXEC SQL free :statemid; efree(Ifx_Result); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't get blob array param"); RETURN_FALSE; } if ((*pblobidarr)->type != IS_ARRAY) { IFXG(sv_sqlcode) = SQLCODE; EXEC SQL DEALLOCATE DESCRIPTOR :i_descrpid; EXEC SQL free :statemid; efree(Ifx_Result); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Blob-parameter not an array"); RETURN_FALSE; } zend_hash_internal_pointer_reset((*pblobidarr)->value.ht); for (i = 1; i <= num_params && (zend_hash_get_current_data((*pblobidarr)->value.ht, (void **) &tmp) == SUCCESS); ++i) { convert_to_long(*tmp); ifx_type = php_intifx_getType((int)(*tmp)->value.lval, &EG(regular_list) TSRMLS_CC); switch (ifx_type) { case TYPE_BLTEXT: case TYPE_BLBYTE: locator = php_intifx_get_blobloc((int)((*tmp)->value.lval), &EG(regular_list) TSRMLS_CC); if (locator == NULL) { IFXG(sv_sqlcode) = SQLCODE; EXEC SQL DEALLOCATE DESCRIPTOR :i_descrpid; EXEC SQL free :statemid; efree(Ifx_Result); php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d is not a Informix blob-result index", (int)((*tmp)->value.lval)); RETURN_FALSE; } if (locator->loc_loctype == LOCFNAME) { locator->loc_oflags=LOC_RONLY; } EXEC SQL SET DESCRIPTOR :i_descrpid VALUE :i DATA = :*locator, TYPE = :loc_t_type; break; case TYPE_CHAR: len = php_intifx_get_char((int)((*tmp)->value.lval), &EG(regular_list), &char_tmp TSRMLS_CC); indicator = 0; if (char_tmp == NULL || len < 0) { indicator = -1; } len++; EXEC SQL SET DESCRIPTOR :descrpid VALUE :i DATA= :char_tmp, LENGTH= :len, INDICATOR= :indicator, TYPE= :sqlchar_type; break; } if (ifx_check() < 0) { char *ifx_err = ifx_error(ifx); IFXG(sv_sqlcode) = SQLCODE; EXEC SQL DEALLOCATE DESCRIPTOR :i_descrpid; EXEC SQL free :statemid; efree(Ifx_Result); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Prepare fails : %s", ifx_err); efree(ifx_err); RETURN_FALSE; } zend_hash_move_forward((*pblobidarr)->value.ht); } if (i - 1 != Ifx_Result->numicols) { EXEC SQL DEALLOCATE DESCRIPTOR :i_descrpid; EXEC SQL free :statemid; efree(Ifx_Result); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Prepare fails : number of created blobs doesn't match placeholders (?)"); RETURN_FALSE; } } Ifx_Result->affected_rows = affected_rows; /* saved estimated from prepare */ for (e = 0; e < 6; e++) { Ifx_Result->sqlerrd[e] = sqlerrd[e]; } } else { /* ## ## SELECT-STATEMENT ## */ ctype = 0; /* preset */ switch (argc) { case 2: break; case 3: if (zend_get_parameters_ex(3, &dummy, &dummy, &cursortype) == FAILURE) { RETURN_FALSE; } convert_to_long_ex(cursortype); ctype = Z_LVAL_PP(cursortype); break; default: WRONG_PARAM_COUNT; break; } Ifx_Result->iscursory = 1; Ifx_Result->affected_rows = affected_rows; /* saved estimated from prepare */ for (e = 0; e < 6; e++) { Ifx_Result->sqlerrd[e] = sqlerrd[e]; } EXEC SQL GET DESCRIPTOR :descrpid :fieldcount = COUNT; if (ifx_check() < 0) { char *ifx_err; IFXG(sv_sqlcode) = SQLCODE; EXEC SQL DEALLOCATE DESCRIPTOR :descrpid; EXEC SQL free :statemid; efree(Ifx_Result); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can not get descriptor %s (%s)", descrpid, (ifx_err = ifx_error(ifx))); efree(ifx_err); RETURN_FALSE; } Ifx_Result->numcols = fieldcount; Ifx_Result->isscroll = Ifx_Result->ishold = 0; if (ctype & IFX_SCROLL) { Ifx_Result->isscroll = 1; } if (ctype & IFX_HOLD) { Ifx_Result->ishold = 1; } } ZEND_REGISTER_RESOURCE(return_value, Ifx_Result, le_result);}/* }}} *//* ----------------------------------------------------------------------** int ifx_do(int resultid)** ** executes a previously prepared query or opens a cursor for it**** returns TRUE on success, false on error** does NOT free $resultid on error !!!** ** also sets (real) affected_rows for non-select statements** for retrieval by ifx_affected_rows** ----------------------------------------------------------------------*//* {{{ proto bool ifx_do(resource resultid) Executes a previously prepared query or opens a cursor for it */PHP_FUNCTION(ifx_do){ zval **result; IFX_RES *Ifx_Result;EXEC SQL BEGIN DECLARE SECTION; char *ifx; /* connection ID */ char *cursorid; /* query cursor id */ char *statemid; /* statement id */ char *descrpid; /* descriptor id */ char *i_descrpid; /* descriptor id */ int fieldcount; /* field count */ int i; /* field index */ short fieldtype; loc_t *locator=NULL; int e;$ifdef HAVE_IFX_IUS; fixed binary 'blob' ifx_lo_t *slocator;$endif;EXEC SQL END DECLARE SECTION; int locind; if (ZEND_NUM_ARGS() != 1 || (zend_get_parameters_ex(1, &result) == FAILURE)) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(Ifx_Result, IFX_RES *, result, -1, "Informix Result", le_result); IFXG(sv_sqlcode) = 0; ifx = Ifx_Result->connecid; cursorid = Ifx_Result->cursorid; statemid = Ifx_Result->statemid; descrpid = Ifx_Result->descrpid; i_descrpid = Ifx_Result->i_descrpid; fieldcount = Ifx_Result->numcols; EXEC SQL set connection :ifx; PHP_IFX_CHECK_CONNECTION(ifx); if (Ifx_Result->iscursory < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Resultindex %d is not a prepared query", Z_LVAL_PP(result)); RETURN_FALSE; } if (Ifx_Result->iscursory == 0) { /* execute immediate */ if (Ifx_Result->paramquery != 0) { EXEC SQL EXECUTE :statemid USING SQL DESCRIPTOR :i_descrpid; } else { EXEC SQL EXECUTE :statemid; } if (ifx_check() < 0) { char *ifx_err = ifx_error(ifx); IFXG(sv_sqlcode) = SQLCODE; php_error_docref(NULL TSRMLS_CC, E_WARNING, "Execute immediate fails: %s", ifx_err); efree(ifx_err); RETURN_FALSE; } Ifx_Result->affected_rows = sqlca.sqlerrd[2]; /* really affected */ for (e = 0; e < 6; e++) { Ifx_Result->sqlerrd[e] = sqlca.sqlerrd[e]; } } else { /* open cursor */ if (Ifx_Result->isscroll) { if (Ifx_Result->ishold) { EXEC SQL DECLARE :cursorid SCROLL CURSOR WITH HOLD FOR :statemid; } else { EXEC SQL DECLARE :cursorid SCROLL CURSOR FOR :statemid; } } else { if (Ifx_Result->ishold) { EXEC SQL DECLARE :cursorid CURSOR WITH HOLD FOR :statemid; } else { EXEC SQL DECLARE :cursorid CURSOR FOR :statemid; } } if (ifx_check() < 0) { char *ifx_err = ifx_error(ifx); IFXG(sv_sqlcode) = SQLCODE; php_error_docref(NULL TSRMLS_CC, E_WARNING, "Declare cursor fails (%s)", ifx_err); efree(ifx_err); RETURN_FALSE; } EXEC SQL OPEN :cursorid; if (ifx_check() < 0) { char *ifx_err = ifx_error(ifx); IFXG(sv_sqlcode) = SQLCODE; php_error_docref(NULL TSRMLS_CC, E_WARNING, "Open cursor fails (%s)", ifx_err); efree(ifx_err); RETURN_FALSE; } /* check for text/blob columns */ locind = 0; for (i = 1; i <= fieldcount; ++i) { EXEC SQL GET DESCRIPTOR :descrpid VALUE :i :fieldtype = TYPE; if ((fieldtype == SQLTEXT) || (fieldtype == SQLBYTES) $ifdef HAVE_IFX_IUS; || (fieldtype == SQLUDTFIXED)$endif; ) { int bid = 0; if (fieldtype == SQLTEXT) { if (IFXG(blobinfile) == 0) { bid = php_intifx_create_blob(TYPE_BLTEXT,BLMODE_INMEM, "", -1, &EG(regular_list) TSRMLS_CC); locator = php_intifx_get_blobloc(bid, &EG(regular_list) TSRMLS_CC); } else { bid = php_intifx_create_blob(TYPE_BLTEXT,BLMODE_INFILE, "", -1, &EG(regular_list) TSRMLS_CC); locator = php_intifx_get_blobloc(bid, &EG(regular_list) TSRMLS_CC); } EXEC SQL SET DESCRIPTOR :descrpid VALUE :i DATA = :*locator; } else if (fieldtype == SQLBYTES) { if (IFXG(blobinfile) == 0) { bid = php_intifx_create_blob(TYPE_BLBYTE,BLMODE_INMEM, "", -1, &EG(regular_list) TSRMLS_CC); locator = php_intifx_get_blobloc(bid, &EG(regular_list) TSRMLS_CC); } else { bid = php_intifx_create_blob(TYPE_BLBYTE,BLMODE_INFILE, "", -1, &EG(regular_list) TSRMLS_CC); locator = php_intifx_get_blobloc(bid, &EG(regular_list) TSRMLS_CC); locator->loc_oflags = LOC_WONLY; } EXEC SQL SET DESCRIPTOR :descrpid VALUE :i DATA = :*locator; } php_intifx_release_blob(locator TSRMLS_CC);$ifdef HAVE_IFX_IUS; if (fieldtype == SQLUDTFIXED) { bid = php_intifxus_new_slob(&EG(regular_list) TSRMLS_CC); slocator = php_intifxus_get_slobloc(bid, &EG(regular_list) TSRMLS_CC); EXEC SQL SET DESCRIPTOR :descrpid VALUE :i DATA = :*slocator; } $endif; Ifx_Result->res_id[locind] = bid; ++locind; } } } /* end open cursor */ RETURN_TRUE;}/* }}} *//* ----------------------------------------------------------------------** string ifx_error([int connection_id]);**** returns the Informix error codes (SQLSTATE & SQLCODE)**** connection id is not checked, but remains for compatibility** ----------------------------------------------------------------------*//* {{{ proto string ifx_error([resource connection_id]) Returns the Informix error codes (SQLSTATE & SQLCODE) */PHP_FUNCTION(ifx_error){ zval **ifx_link; int id; switch(ZEND_NUM_ARGS()) { case 0: id = IFXG(default_link); break; case 1: if (zend_get_parameters_ex(1, &ifx_link) == FAILURE) { RETURN_FALSE; } break; default: WRONG_PARAM_COUNT; break; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -