예제 #1
0
/*getRowData - Retrieve the data from the current row.
Output: False on error*/
Bool DBCursor_ORACLE::getRowData()
{
	for (unsigned int i=0; i<fieldCount; i++)
	{
		DBField_ORACLE *ofield = (DBField_ORACLE *)fields[i];

		ofield -> data = ofield -> databuffer + (ofield -> maxlength * FetchedNum);
		ofield -> dataSize = ofield -> dsize[FetchedNum];
		
		if (ofield -> extraData)
		{
			free(ofield -> extraData);
			ofield -> extraData = NULL;
		}

		if (ofield -> errorcode[FetchedNum] != 1405)
			ofield -> isNull = False;

		if (ofield->errorcode[FetchedNum] == 1405)
			ofield -> isNull = True;
		else if (!cacherows && ofield->errorcode[FetchedNum] == 1406 && (ofield->externaltype == RAW_TYPE || ofield->externaltype == LRAW_TYPE))
		{
			int lflength = (size_t)ofield->indp[FetchedNum];
			ofield->extraData = (char *)malloc(RAWSIZE*2);
			memcpy(ofield->extraData,ofield->data,RAWSIZE);
			sb4 offset = RAWSIZE;
			sb2 result;
			ub4 ret_len;
			while (True)
			{
				result = oflng(ORACLE_res, i+1, (ub1 *)(ofield->extraData + offset), RAWSIZE, ofield->externaltype, &ret_len,offset);
				if (result || ret_len <= 0)
					break;

				offset += ret_len;
				ofield->extraData = (char *)realloc(ofield->extraData,offset + RAWSIZE);
			}
			ofield->data = (char *)(ofield->extraData);
			ofield->dataSize = offset;
		}
		else if (ofield->errorcode[FetchedNum] != 0)
			ofield -> isNull = True;
	}
	return True;
}
예제 #2
0
/* {{{ proto mixed ora_getcolumn(int cursor, int column)
   Get data from a fetched row */
void php3_Ora_GetColumn(INTERNAL_FUNCTION_PARAMETERS)
{								/* cursor_index, column_index */
	pval *argv[2];
	int colno;
	oraCursor *cursor = NULL;
	oraColumn *column = NULL;
	sb2 type;

	if (ARG_COUNT(ht) != 2 || getParametersArray(ht, 2, argv) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	convert_to_long(argv[0]);

	/* Find the cursor */
	if ((cursor = ora_get_cursor(list, argv[0]->value.lval)) == NULL) {
		RETURN_FALSE;
	}

	if (cursor->ncols == 0){
		php3_error(E_WARNING, "No tuples available at this cursor index");
		RETURN_FALSE;
	}

	convert_to_long(argv[1]);
	colno = argv[1]->value.lval;        

	if (colno >= cursor->ncols){
		php3_error(E_WARNING, "Column index larger than number of columns");
		RETURN_FALSE;
	}

	if (colno < 0){
		php3_error(E_WARNING, "Column numbering starts at 0");
		RETURN_FALSE;
	}

	if (cursor->fetched == 0){
		if (ofetch(&cursor->cda)) {
			if (cursor->cda.rc != NO_DATA_FOUND) {
				php3_error(E_WARNING, "Ora_Fetch failed (%s)",
						   ora_error(&cursor->cda));
			}
			RETURN_FALSE;
		}
		cursor->fetched++;		
	}

 	column = &cursor->columns[colno]; 

 	type = column->dbtype; 

	if (column->col_retcode != 0 && column->col_retcode != 1406) {
		/* So error fetching column.  The most common is 1405, a NULL
		 * was retreived.  1406 is ASCII or string buffer data was
		 * truncated. The converted data from the database did not fit
		 * into the buffer.  Since we allocated the buffer to be large
		 * enough, this should not occur.  Anyway, we probably want to
		 * return what we did get, in that case
		 */
		RETURN_FALSE;
	} else {
		switch(type)
			{
			case SQLT_CHR:
			case SQLT_NUM:
			case SQLT_INT: 
			case SQLT_FLT:
			case SQLT_STR:
			case SQLT_UIN:
			case SQLT_AFC:
			case SQLT_AVC:
			case SQLT_DAT:
				RETURN_STRINGL(column->buf, min(column->col_retlen, column->dsize), 1);
			case SQLT_LNG:
			case SQLT_LBI:
#if 0
                {
                ub4 ret_len;
                /* XXX 64k max for LONG and LONG RAW */
                oflng(&cursor->cda, (sword)(colno + 1), column->buf, DB_SIZE, 1,
                      &ret_len, 0);
                RETURN_STRINGL(column->buf, ret_len, 1);
                } 
#else
					{ 
						ub4 ret_len;
						int offset = column->col_retlen;
						sb2 result;
						
						if (column->col_retcode == 1406) { /* truncation -> get the rest! */
							while (1) {
								column->buf = erealloc(column->buf,offset + DB_SIZE + 1);
								
								if (! column->buf) {
									offset = 0;
									break;
								}
								
								result = oflng(&cursor->cda, 
											   (sword)(colno + 1),
											   column->buf + offset, 
											   DB_SIZE, 
											   1,
											   &ret_len, 
											   offset);
								if (result) {
									break;
								}
								
								if (ret_len <= 0) {
									break;
								}
								
								offset += ret_len;
							}
						}
						if (column->buf && offset) {
							RETURN_STRINGL(column->buf, offset, 1);
						} else {
							RETURN_FALSE;
						}
					}
#endif
			default:
				php3_error(E_WARNING,
						   "Ora_GetColumn found invalid type (%d)", type);
				RETURN_FALSE;
			}
	}
}
예제 #3
0
/* {{{ proto int ora_fetch_into(int cursor, array result [, int flags])
   Fetch a row into the specified result array */
void php3_Ora_FetchInto(INTERNAL_FUNCTION_PARAMETERS)
{
	pval     *arg1, *arr, *flg, *tmp;
	oraCursor *cursor;
	int i;
	int flags = 0;

	switch(ARG_COUNT(ht)){
		case 2:
			if (getParameters(ht, 2, &arg1, &arr) == FAILURE) {
				WRONG_PARAM_COUNT;
			}
			break;

		case 3:
			if (getParameters(ht, 3, &arg1, &arr, &flg) == FAILURE) {
				WRONG_PARAM_COUNT;
			}
			convert_to_long(flg);
			flags = flg->value.lval;
			break;

		default:
			WRONG_PARAM_COUNT;
			break;
	}

	if (!ParameterPassedByReference(ht, 2)){
		php3_error(E_WARNING, "Array not passed by reference in call to ora_fetch_into()");
		RETURN_FALSE;
	}

	convert_to_long(arg1);

	/* Find the cursor */
	if ((cursor = ora_get_cursor(list, arg1->value.lval)) == NULL) {
		RETURN_FALSE;
	}

	if (cursor->ncols == 0){
		php3_error(E_WARNING, "No tuples available on this cursor");
		RETURN_FALSE;
	}


	if (ofetch(&cursor->cda)) {
		if (cursor->cda.rc != NO_DATA_FOUND) {
			php3_error(E_WARNING, "Ora_Fetch_Into failed (%s)",
					   ora_error(&cursor->cda));
		}
		RETURN_FALSE;
	}
	cursor->fetched++;

	if (arr->type != IS_ARRAY){
		php3tls_pval_destructor(arr);
		if (array_init(arr) == FAILURE){
			php3_error(E_WARNING, "Can't convert to type Array");
			RETURN_FALSE;
		}
	}

 	_php3_hash_internal_pointer_reset(arr->value.ht); 

#if PHP_API_VERSION < 19990421
	tmp = emalloc(sizeof(pval));
#endif

	for (i = 0; i < cursor->ncols; i++) {
       
		if (cursor->columns[i].col_retcode == 1405) {
			if (!(flags&ORA_FETCHINTO_NULLS)){
				continue; /* don't add anything for NULL columns, unless the calles wants it */
			} else {
				tmp->value.str.val = empty_string;
				tmp->value.str.len = 0;
			}
		} else if (cursor->columns[i].col_retcode != 0 &&
				   cursor->columns[i].col_retcode != 1406) {
			/* So error fetching column.  The most common is 1405, a NULL */
			/* was retreived.  1406 is ASCII or string buffer data was */
			/* truncated. The converted data from the database did not fit */
			/* into the buffer.  Since we allocated the buffer to be large */
			/* enough, this should not occur.  Anyway, we probably want to */
			/* return what we did get, in that case */
			RETURN_FALSE;
		} else {
#if PHP_API_VERSION >= 19990421
			MAKE_STD_ZVAL(tmp);
#endif

			tmp->type = IS_STRING;
			tmp->value.str.len = 0;

			switch(cursor->columns[i].dbtype) {
				case SQLT_LNG:
				case SQLT_LBI:
					{ 
						ub4 ret_len;
						int offset = cursor->columns[i].col_retlen;
						sb2 result;
						
						if (cursor->columns[i].col_retcode == 1406) { /* truncation -> get the rest! */
							while (1) {
								cursor->columns[i].buf = erealloc(cursor->columns[i].buf,offset + DB_SIZE + 1);
								
								if (! cursor->columns[i].buf) {
									offset = 0;
									break;
								}
								
								result = oflng(&cursor->cda, 
											   (sword)(i + 1),
											   cursor->columns[i].buf + offset, 
											   DB_SIZE, 
											   1,
											   &ret_len, 
											   offset);
								if (result) {
									break;
								}
								
								if (ret_len <= 0) {
									break;
								}
								
								offset += ret_len;
							}
						}
						if (cursor->columns[i].buf && offset) {
							tmp->value.str.len = offset;
						} else {
							tmp->value.str.len = 0;
						}
					}
					break;
				default:
					tmp->value.str.len = min(cursor->columns[i].col_retlen,
											 cursor->columns[i].dsize);
					break;
			}
			tmp->value.str.val = estrndup(cursor->columns[i].buf,tmp->value.str.len);
		}

		if (flags&ORA_FETCHINTO_ASSOC){
#if PHP_API_VERSION >= 19990421
			_php3_hash_update(arr->value.ht, cursor->columns[i].cbuf, cursor->columns[i].cbufl+1, (void *) &tmp, sizeof(pval*), NULL);
#else
			_php3_hash_update(arr->value.ht, cursor->columns[i].cbuf, cursor->columns[i].cbufl+1, (void *) tmp, sizeof(pval), NULL);
#endif
		} else {
#if PHP_API_VERSION >= 19990421
			_php3_hash_index_update(arr->value.ht, i, (void *) &tmp, sizeof(pval*), NULL);
#else
			_php3_hash_index_update(arr->value.ht, i, (void *) tmp, sizeof(pval), NULL);
#endif
		}

	}

#if PHP_API_VERSION < 19990421
	efree(tmp); 
#endif

	RETURN_LONG(cursor->ncols); 
}