⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 birdstep.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	/* Success query */	stat = SQLNumResultCols(res->hstmt,&cols);	if ( stat != SQL_SUCCESS ) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLNumResultCols return %d",stat);		SQLFreeStmt(res->hstmt,SQL_DROP);		efree(res);		RETURN_FALSE;	}	if ( !cols ) { /* Was INSERT, UPDATE, DELETE, etc. query */		stat = SQLRowCount(res->hstmt,&rows);		if ( stat != SQL_SUCCESS ) {			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLNumResultCols return %d",stat);			SQLFreeStmt(res->hstmt,SQL_DROP);			efree(res);			RETURN_FALSE;		}		SQLFreeStmt(res->hstmt,SQL_DROP);		efree(res);		RETURN_LONG(rows);	} else {  /* Was SELECT query */		res->values = (VResVal *)emalloc(sizeof(VResVal)*cols);		res->numcols = cols;		for ( i = 0; i < cols; i++ ) {			SQLColAttributes(res->hstmt,i+1,SQL_COLUMN_NAME,			   res->values[i].name,sizeof(res->values[i].name),			   &colnamelen,NULL);			SQLColAttributes(res->hstmt,i+1,SQL_COLUMN_TYPE,			   NULL,0,NULL,&res->values[i].valtype);			switch ( res->values[i].valtype ) {				case SQL_LONGVARBINARY:				case SQL_LONGVARCHAR:					res->values[i].value = NULL;					continue;				default:					break;			}			SQLColAttributes(res->hstmt,i+1,SQL_COLUMN_DISPLAY_SIZE,			   NULL,0,NULL,&coldesc);			res->values[i].value = (char *)emalloc(coldesc+1);			SQLBindCol(res->hstmt,i+1,SQL_C_CHAR, res->values[i].value,coldesc+1, &res->values[i].vallen);		}	}	res->fetched = 0;	indx = birdstep_add_result(list,res,conn);	RETURN_LONG(indx);}/* }}} *//* {{{ proto bool birdstep_fetch(int index) */PHP_FUNCTION(birdstep_fetch){	zval **ind;	Vresult *res;	RETCODE stat;	UDWORD  row;	UWORD   RowStat[1];	if ( ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &ind) == FAILURE ) {		WRONG_PARAM_COUNT;	}	PHP_GET_BIRDSTEP_RES_IDX(ind);	stat = SQLExtendedFetch(res->hstmt,SQL_FETCH_NEXT,1,&row,RowStat);	if ( stat == SQL_NO_DATA_FOUND ) {		SQLFreeStmt(res->hstmt,SQL_DROP);		birdstep_del_result(list,Z_LVAL_PP(ind));		RETURN_FALSE;	}	if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLFetch return error");		SQLFreeStmt(res->hstmt,SQL_DROP);		birdstep_del_result(list,Z_LVAL_PP(ind));		RETURN_FALSE;	}	res->fetched = 1;	RETURN_TRUE;}/* }}} *//* {{{ proto mixed birdstep_result(int index, int col) */PHP_FUNCTION(birdstep_result){	zval **ind, **col;	Vresult *res;	RETCODE stat;	int i,sql_c_type;	UDWORD row;	UWORD RowStat[1];	SWORD indx = -1;	char *field = NULL;	if ( ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &ind, &col) == FAILURE ) {		WRONG_PARAM_COUNT;	}	PHP_GET_BIRDSTEP_RES_IDX(ind);	if ( Z_TYPE_PP(col) == IS_STRING ) {		field = Z_STRVAL_PP(col);	} else {		convert_to_long_ex(col);		indx = Z_LVAL_PP(col);	}	if ( field ) {		for ( i = 0; i < res->numcols; i++ ) {			if ( !strcasecmp(res->values[i].name,field)) {				indx = i;				break;			}		}		if ( indx < 0 ) {			php_error_docref(NULL TSRMLS_CC, E_WARNING,  "Field %s not found",field);			RETURN_FALSE;		}	} else {		if ( indx < 0 || indx >= res->numcols ) {			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Field index not in range");			RETURN_FALSE;		}	}	if ( !res->fetched ) {		stat = SQLExtendedFetch(res->hstmt,SQL_FETCH_NEXT,1,&row,RowStat);		if ( stat == SQL_NO_DATA_FOUND ) {			SQLFreeStmt(res->hstmt,SQL_DROP);			birdstep_del_result(list,Z_LVAL_PP(ind));			RETURN_FALSE;		}		if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLFetch return error");			SQLFreeStmt(res->hstmt,SQL_DROP);			birdstep_del_result(list,Z_LVAL_PP(ind));			RETURN_FALSE;		}		res->fetched = 1;	}	switch ( res->values[indx].valtype ) {		case SQL_LONGVARBINARY:			sql_c_type = SQL_C_BINARY;			goto l1;		case SQL_LONGVARCHAR:			sql_c_type = SQL_C_CHAR;l1:			if ( !res->values[indx].value ) {				res->values[indx].value = emalloc(4096);			}			stat = SQLGetData(res->hstmt,indx+1,sql_c_type,				res->values[indx].value,4095,&res->values[indx].vallen);			if ( stat == SQL_NO_DATA_FOUND ) {				SQLFreeStmt(res->hstmt,SQL_DROP);				birdstep_del_result(list,Z_LVAL_PP(ind));				RETURN_FALSE;			}			if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLGetData return error");				SQLFreeStmt(res->hstmt,SQL_DROP);				birdstep_del_result(list,Z_LVAL_PP(ind));				RETURN_FALSE;			}			if ( res->values[indx].valtype == SQL_LONGVARCHAR ) {				RETURN_STRING(res->values[indx].value,TRUE);			} else {				RETURN_LONG((long)res->values[indx].value);			}		default:			if ( res->values[indx].value != NULL ) {				RETURN_STRING(res->values[indx].value,TRUE);			}	}}/* }}} *//* {{{ proto bool birdstep_freeresult(int index) */PHP_FUNCTION(birdstep_freeresult){	zval **ind;	Vresult *res;	if ( ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &ind) == FAILURE ) {		WRONG_PARAM_COUNT;	}	PHP_GET_BIRDSTEP_RES_IDX(ind);	SQLFreeStmt(res->hstmt,SQL_DROP);	birdstep_del_result(list,Z_LVAL_PP(ind));	RETURN_TRUE;}/* }}} *//* {{{ proto bool birdstep_autocommit(int index) */PHP_FUNCTION(birdstep_autocommit){	zval **id;	RETCODE stat;	VConn *conn;	if ( ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &id) == FAILURE ) {		WRONG_PARAM_COUNT;	}	PHP_BIRDSTEP_CHK_LNK(id);	stat = SQLSetConnectOption(conn->hdbc,SQL_AUTOCOMMIT,SQL_AUTOCOMMIT_ON);	if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Set autocommit_on option failure");		RETURN_FALSE;	}	RETURN_TRUE;}/* }}} *//* {{{ proto bool birdstep_off_autocommit(int index) */PHP_FUNCTION(birdstep_off_autocommit){	zval **id;	RETCODE stat;	VConn *conn;	if ( ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &id) == FAILURE ) {		WRONG_PARAM_COUNT;	}	PHP_BIRDSTEP_CHK_LNK(id);	stat = SQLSetConnectOption(conn->hdbc,SQL_AUTOCOMMIT,SQL_AUTOCOMMIT_OFF);	if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Set autocommit_off option failure");		RETURN_FALSE;	}	RETURN_TRUE;}/* }}} *//* {{{ proto bool birdstep_commit(int index) */PHP_FUNCTION(birdstep_commit){	zval **id;	RETCODE stat;	VConn *conn;	if ( ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &id) == FAILURE ) {		WRONG_PARAM_COUNT;	}	PHP_BIRDSTEP_CHK_LNK(id)	stat = SQLTransact(NULL,conn->hdbc,SQL_COMMIT);	if ( stat != SQL_SUCCESS ) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Commit failure");		RETURN_FALSE;	}	RETURN_TRUE;}/* }}} *//* {{{ proto bool birdstep_rollback(int index) */PHP_FUNCTION(birdstep_rollback){	zval **id;	RETCODE stat;	VConn *conn;	if ( ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &id) == FAILURE ) {		WRONG_PARAM_COUNT;	}	PHP_BIRDSTEP_CHK_LNK(id);	stat = SQLTransact(NULL,conn->hdbc,SQL_ROLLBACK);	if ( stat != SQL_SUCCESS ) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Rollback failure");		RETURN_FALSE;	}	RETURN_TRUE;}/* }}} *//* {{{ proto string birdstep_fieldname(int index, int col) */PHP_FUNCTION(birdstep_fieldname){	zval **ind, **col;	Vresult *res;	SWORD indx;	if ( ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &ind, &col) == FAILURE ) {		WRONG_PARAM_COUNT;	}	PHP_GET_BIRDSTEP_RES_IDX(ind);	convert_to_long_ex(col);	indx = Z_LVAL_PP(col);	if ( indx < 0 || indx >= res->numcols ) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Field index not in range");		RETURN_FALSE;	}	RETURN_STRING(res->values[indx].name,TRUE);}/* }}} *//* {{{ proto int birdstep_fieldnum(int index) */PHP_FUNCTION(birdstep_fieldnum){	zval **ind;	Vresult *res;	if ( ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &ind) == FAILURE ) {		WRONG_PARAM_COUNT;	}	PHP_GET_BIRDSTEP_RES_IDX(ind);	RETURN_LONG(res->numcols);}/* }}} */#endif /* HAVE_BIRDSTEP *//* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -