📄 ifx.ec
字号:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Out of memory allocating IFX_RES"); EXEC SQL free :statemid; 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) { 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 (Z_TYPE_PP(pblobidarr) != 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 is not an array"); RETURN_FALSE; } zend_hash_internal_pointer_reset((*pblobidarr)->value.ht); for (i = 1; i <= Ifx_Result->numicols && (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 an 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 :i_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, "Execute immediate fails : %s", ifx_err); efree(ifx_err); RETURN_FALSE; } zend_hash_move_forward((*pblobidarr)->value.ht); } Ifx_Result->paramquery=1; 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, "Execute immediate fails : number of created blobs doesn't match placeholders (?)"); RETURN_FALSE; } 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; if (Ifx_Result->numicols > 0) { EXEC SQL DEALLOCATE DESCRIPTOR :i_descrpid; } EXEC SQL free :statemid; efree(Ifx_Result); 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 { /* ## ## 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->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 = ifx_error(ifx); 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); 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; } /* * ifx_do() part */ 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; EXEC SQL DEALLOCATE DESCRIPTOR :descrpid; EXEC SQL free :statemid; efree(Ifx_Result); 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; EXEC SQL DEALLOCATE DESCRIPTOR :descrpid; EXEC SQL free :statemid; EXEC SQL free :cursorid; efree(Ifx_Result); 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); } 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; } } } ZEND_REGISTER_RESOURCE(return_value, Ifx_Result, le_result);}/* }}} *//* ----------------------------------------------------------------------** int ifx_prepare(string query, int connid, ** [, int cursortype] [, array blobidarry])**** $hold, $scroll are optional and valid only for select queries** $blobidarray is optional, an array of blob id's**** prepares query $query on connection $connid** select queries accept an optional cursortype param: IFX_SCROLL, IFX_HOLD (or'ed mask)** blobsupport: mark the blob-column with ? and add a blob-id-functionparameter** example: ifx_query("insert into catalog (stock_num, manu_code ,cat_descr,** cat_picture) values(1,'HRO',?,?)",$cid,$bid1,$bid2);** ** returns a "result id" on success or FALSE on error** also sets "affected_rows for retrieval by ifx_affected_rows** ----------------------------------------------------------------------*//* {{{ proto resource ifx_prepare(string query, resource connid [, int cursortype] [, array idarray]) Prepare a query on a given connection */PHP_FUNCTION(ifx_prepare){ zval **query, **ifx_link, **cursortype, **dummy; int id=-1; IFX_RES *Ifx_Result;EXEC SQL BEGIN DECLARE SECTION; char *ifx; /* connection ID */ char cursorid[32]; /* query cursor id */ char statemid[32]; /* statement id */ char descrpid[32]; /* descriptor id */ char i_descrpid[32]; /* input descriptor binding */ char *statement; /* query text */ int fieldcount; /* field count */ int i; /* field index */ loc_t *locator; int loc_t_type=CLOCATORTYPE; /* WORKAROUND: TYPE=CLOCATORTYPE doesn't work, */ int sqlchar_type=SQLCHAR; /* don't ask me, why. */ char *char_tmp; long len; int indicator; long sqlerrd[6]; int e; int desc_count;EXEC SQL END DECLARE SECTION; int ctype; int affected_rows; int query_type; int cursoryproc; int argc=ZEND_NUM_ARGS(); long ifx_type; int num_params; if (argc < 2 || zend_get_parameters_ex(argc, &query, &ifx_link, &dummy, &dummy) == FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE2(ifx, char *, ifx_link, id, "Informix link", le_link, le_plink); IFXG(sv_sqlcode) = 0; affected_rows = -1; /* invalid */ convert_to_string_ex(query); statement = Z_STRVAL_PP(query); IFXG(cursorid)++; sprintf(statemid, "statem%x_%x", IFX_THRD_ID, IFXG(cursorid)); sprintf(cursorid, "cursor%x_%x", IFX_THRD_ID, IFXG(cursorid)); sprintf(descrpid, "descrp%x_%x", IFX_THRD_ID, IFXG(cursorid)); sprintf(i_descrpid, "i_descrp%x_%x", IFX_THRD_ID,IFXG(cursorid)); EXEC SQL set connection :ifx; PHP_IFX_CHECK_CONNECTION(ifx); EXEC SQL PREPARE :statemid FROM :statement; if (ifx_check() < 0) { IFXG(sv_sqlcode) = SQLCODE; php_error_docref(NULL TSRMLS_CC, E_WARNING, "Prepare fails (%s)", ifx_error(ifx)); RETURN_FALSE; } affected_rows = sqlca.sqlerrd[0]; /* save estimated affected rows */ for (e = 0; e < 6; e++) { sqlerrd[e] = sqlca.sqlerrd[e]; } num_params = php_intifx_preparse(statement TSRMLS_CC); Ifx_Result = (IFX_RES *) emalloc(sizeof(IFX_RES)); if (Ifx_Result == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Out of memory allocating IFX_RES"); EXEC SQL free :statemid;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -