示例#1
0
/* {{{ proto string ora_error(int cursor_or_connection)
   Get an Oracle error message */
void php3_Ora_Error(INTERNAL_FUNCTION_PARAMETERS)
{
	pval *arg;
	oraCursor *cursor;
	oraConnection *conn;
	int argc = ARG_COUNT(ht);

	if (argc < 0 || argc > 1 || getParametersArray(ht, argc, &arg) == FAILURE) {
		WRONG_PARAM_COUNT;
	}
	
	if (argc == 1) {
		convert_to_long(arg);
		if ((cursor = ora_get_cursor(list, arg->value.lval)) != NULL) {
			return_value->type = IS_STRING;
			return_value->value.str.val = estrdup(ora_error(&cursor->cda));
			return_value->value.str.len = strlen(return_value->value.str.val);
		} else if ((conn = ora_get_conn(list,plist, arg->value.lval)) != NULL) {
			return_value->type = IS_STRING;
			return_value->value.str.val = estrdup(ora_error(&conn->lda));
			return_value->value.str.len = strlen(return_value->value.str.val);
		}
	} else {
        return_value->type = IS_STRING;
        return_value->value.str.val = estrdup(ora_error(&db_err_conn.lda));
        return_value->value.str.len = strlen(return_value->value.str.val);
    }
}
示例#2
0
/* {{{ proto int ora_parse(int cursor, string sql_statement [, int defer])
   Parse an Oracle SQL statement */
void php3_Ora_Parse(INTERNAL_FUNCTION_PARAMETERS)
{	
     /* cursor_ind, sql_statement [, defer] */
	int argc;
	pval *argv[3];
	oraCursor *cursor;
	sword defer = 0;
	text *query;

	argc = ARG_COUNT(ht);
	if ((argc != 2 && argc != 3) || getParametersArray(ht, argc, argv) == FAILURE) {
		WRONG_PARAM_COUNT;
	}
	convert_to_long(argv[0]);
	convert_to_string(argv[1]);

	if (argc == 3) {
		convert_to_long(argv[2]);
		if (argv[2]->value.lval != 0) {
			defer = DEFER_PARSE;
		}
	}

 	query = (text *) estrndup(argv[1]->value.str.val,argv[1]->value.str.len);

	if (query == NULL) {
		php3_error(E_WARNING, "Invalid query");
		RETURN_FALSE;
	}
	if (!(cursor = ora_get_cursor(list, argv[0]->value.lval))){
		efree(query);
		RETURN_FALSE;
	}

	if (cursor->query) {
		efree(cursor->query);
	}
	cursor->query = query;
	cursor->fetched = 0;
	if(cursor->params && cursor->nparams > 0){
		_php3_hash_destroy(cursor->params);
		efree(cursor->params);
		cursor->params = NULL;
		cursor->nparams = 0;
	}

	if (oparse(&cursor->cda, query, (sb4) - 1, defer, VERSION_7)) {
		php3_error(E_WARNING, "Ora_Parse failed (%s)",
				   ora_error(&cursor->cda));
		RETURN_FALSE;
	}
	RETURN_TRUE;
}
示例#3
0
/* {{{ proto int ora_errorcode(int cursor_or_connection)
   Get an Oracle error code */
void php3_Ora_ErrorCode(INTERNAL_FUNCTION_PARAMETERS)
{
	pval *arg;
	oraCursor *cursor;
	oraConnection *conn;
	int argc = ARG_COUNT(ht);

	if (argc < 0 || argc > 1 || getParametersArray(ht, argc, &arg) == FAILURE) {
		WRONG_PARAM_COUNT;
	}
	
	if (argc == 1) {
		convert_to_long(arg);
		if ((cursor = ora_get_cursor(list, arg->value.lval)) != NULL) {
			RETURN_LONG(cursor->cda.rc);
		} else if ((conn = ora_get_conn(list,plist, arg->value.lval)) != NULL) {
			RETURN_LONG(conn->lda.rc);
		} 
	} else {
        RETURN_LONG(db_err_conn.lda.rc);
    }

}
示例#4
0
/* {{{ proto string ora_columnname(int cursor, int column)
   Get the name of an Oracle result column */
void php3_Ora_ColumnName(INTERNAL_FUNCTION_PARAMETERS)
{								/* cursor_index, column_index */
	pval *argv[2];
	int cursor_ind;
	oraCursor *cursor = NULL;

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

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

	convert_to_long(argv[1]);
	
	if (cursor->ncols == 0){
		php3_error(E_WARNING, "No tuples available at this cursor index");
		RETURN_FALSE;
	}
        
	if (argv[1]->value.lval >= cursor->ncols){
		php3_error(E_WARNING, "Column index larger than number of columns");
		RETURN_FALSE;
	}

	if (argv[1]->value.lval < 0){
		php3_error(E_WARNING, "Column numbering starts at 0");
		RETURN_FALSE;
	}
        
	RETURN_STRINGL(cursor->columns[argv[1]->value.lval].cbuf,
				   cursor->columns[argv[1]->value.lval].cbufl,1);
}
示例#5
0
/* {{{ proto mixed com_invoke(int module, string handler_name [, mixed arg [, ...]])
   Invokes a COM module */
void php3_COM_invoke(INTERNAL_FUNCTION_PARAMETERS)
{
	pval **arguments;
	IDispatch *i_dispatch;
	int type;
	DISPID dispid;
	HRESULT hr;
	OLECHAR *funcname;
	char *error_message;
	VARIANTARG *variant_args;
	int arg_count = ARG_COUNT(ht), current_arg, current_variant;
	DISPPARAMS dispparams;
	VARIANTARG var_result;

	if (arg_count<2) {
		WRONG_PARAM_COUNT;
	}
	arguments = (pval **) emalloc(sizeof(pval *) * arg_count);
	if (getParametersArray(ht, arg_count, arguments)==FAILURE) {
		efree(arguments);
		RETURN_FALSE;
	}

	/* obtain i_dispatch interface */
	convert_to_long(arguments[0]);
	i_dispatch = php3_list_find(arguments[0]->value.lval,&type);
	if (!i_dispatch || (type!=le_idispatch)) {
		php3_error(E_WARNING,"%d is not a COM object handler", arguments[0]->value.lval);
		efree(arguments);
		RETURN_FALSE;
	}

	/* obtain property/method handler */
	convert_to_string(arguments[1]);
	funcname = _php3_C_str_to_unicode(arguments[1]->value.str.val, arguments[1]->value.str.len);

	hr = i_dispatch->lpVtbl->GetIDsOfNames(i_dispatch, &IID_NULL, &funcname,
											1, LOCALE_SYSTEM_DEFAULT, &dispid);

	if (FAILED(hr)) {
		error_message = _php3_COM_error_message(hr);
		php3_error(E_WARNING,"Unable to lookup %s:  %s\n", arguments[1]->value.str.val, error_message);
		LocalFree(error_message);
		efree(funcname);
		efree(arguments);
		RETURN_FALSE;
	}

	arg_count -= 2;
	variant_args = (VARIANTARG *) emalloc(sizeof(VARIANTARG)*arg_count);

	for (current_arg=0; current_arg<arg_count; current_arg++) {
		current_variant = arg_count - current_arg - 1;
		_php3_pval_to_variant(arguments[2+current_arg], &variant_args[current_variant]);
	}


	dispparams.rgvarg = variant_args;
	dispparams.rgdispidNamedArgs = NULL;
	dispparams.cArgs = arg_count;
	dispparams.cNamedArgs = 0;

	hr = i_dispatch->lpVtbl->Invoke(i_dispatch, dispid, &IID_NULL,
									LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD,
									&dispparams, &var_result, NULL, 0);

	if (FAILED(hr)) {
		error_message = _php3_COM_error_message(hr);
		php3_error(E_WARNING,"Invoke() failed:  %s\n", error_message);
		LocalFree(error_message);
		efree(funcname);
		efree(arguments);
		efree(variant_args);
		RETURN_FALSE;
	}

	_php3_variant_to_pval(&var_result, return_value);

	efree(arguments);
	efree(variant_args);
	efree(funcname);
}
示例#6
0
/* {{{ proto int ora_do(int connection, int cursor)
   Parse and execute a statement and fetch first result row */ 
void php3_Ora_Do(INTERNAL_FUNCTION_PARAMETERS)
{
	pval *argv[2];
	oraConnection *conn = NULL;
	oraCursor *cursor = NULL;
	text *query;

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

	convert_to_long(argv[0]);
	convert_to_string(argv[1]);

	conn = ora_get_conn(list,plist, argv[0]->value.lval);
	if (conn == NULL) {
		RETURN_FALSE;
	}

	if ((cursor = (oraCursor *)emalloc(sizeof(oraCursor))) == NULL){
		php3_error(E_WARNING, "Out of memory");
		RETURN_FALSE;
	}

	memset(cursor, 0, sizeof(oraCursor));

        query = (text *) estrndup(argv[1]->value.str.val,argv[1]->value.str.len);

        if (query == NULL) {
                php3_error(E_WARNING, "Invalid query in Ora_Do");
                RETURN_FALSE;
        }

        cursor->query = query;

	if (oopen(&cursor->cda, &conn->lda, (text *) 0, -1, -1, (text *) 0, -1)) {
		php3_error(E_WARNING, "Unable to open new cursor (%s)",
				   ora_error(&cursor->cda));
		efree(cursor);
		RETURN_FALSE;
	}
	cursor->open = 1;
	cursor->conn_ptr = conn;	
	cursor->conn_id = argv[0]->value.lval;	
	
	/* Prepare stmt */

	if (oparse(&cursor->cda, query, (sb4) - 1, 1, VERSION_7)){
		php3_error(E_WARNING, "Ora_Do failed (%s)",
				   ora_error(&cursor->cda));
		_close_oracur(cursor);
		RETURN_FALSE;
	}

	/* Execute stmt (and fetch 1st row for selects) */
	if (cursor->cda.ft == FT_SELECT) {
		if (ora_describe_define(cursor) < 0){
			/* error message is given by ora_describe_define() */
			_close_oracur(cursor);
			RETURN_FALSE;
		}
		if (oexfet(&cursor->cda, 1, 0, 0)) {
			php3_error(E_WARNING, "Ora_Do failed (%s)",
					   ora_error(&cursor->cda));
			_close_oracur(cursor);
			RETURN_FALSE;
		}
		cursor->fetched = 1;
	} else {
		if (oexec(&cursor->cda)) {
			php3_error(E_WARNING, "Ora_Do failed (%s)",
					   ora_error(&cursor->cda));
			_close_oracur(cursor);
			RETURN_FALSE;
		}
	}

	RETURN_RESOURCE(ora_add_cursor(list, cursor));
}
示例#7
0
/* {{{ proto int ora_bind(int cursor, string php_variable_name, string sql_parameter_name, int length [, int type])
   Bind a PHP variable to an Oracle parameter */
void php3_Ora_Bind(INTERNAL_FUNCTION_PARAMETERS)
{ /* cursor_ind, php_var_name, sql_var_name, data_len [, inout]*/
	/* inout: 0 = in/out, 1 = in, 2 = out */
	int argc;
	pval *argv[5];
	oraParam *newparam, *paramptr;
	oraCursor *cursor;
	char *paramname;

	argc = ARG_COUNT(ht);
	if (argc < 4 || argc > 5 || getParametersArray(ht, argc, argv) == FAILURE){
		WRONG_PARAM_COUNT;
	}
	convert_to_long(argv[0]);
	convert_to_string(argv[1]);
	convert_to_string(argv[2]);
	convert_to_long(argv[3]);
		
	cursor = ora_get_cursor(list, argv[0]->value.lval);
	if (cursor == NULL) {
		php3_error(E_WARNING, "Invalid cursor index %d",
				   argv[0]->value.lval);
		RETURN_FALSE;
	}

	if(cursor->params == NULL){
		cursor->params = (HashTable *)emalloc(sizeof(HashTable));
		if (!cursor->params ||
			_php3_hash_init(cursor->params, 19, NULL,
							HASH_DTOR pval_ora_param_destructor, 0) == FAILURE) {
			php3_error(E_ERROR, "Unable to initialize parameter list");
			RETURN_FALSE;
		}
	}
	if((newparam = (oraParam *)emalloc(sizeof(oraParam))) == NULL){
		php3_error(E_WARNING, "Out of memory for parameter");
		RETURN_FALSE;
	}

	if((paramname = estrndup(argv[1]->value.str.val, argv[1]->value.str.len)) == NULL){
		php3_error(E_WARNING, "Out of memory for parametername");
		efree(newparam);
		RETURN_FALSE;
	}

	if (_php3_hash_add(cursor->params, paramname, argv[1]->value.str.len + 1, newparam, sizeof(oraParam), (void **)&paramptr) == FAILURE) {
		/* XXX _php3_hash_destroy */
		efree(paramname);
		efree(newparam);
		php3_error(E_ERROR, "Could not make parameter placeholder");
		RETURN_FALSE;
	}

	efree(newparam);
	efree(paramname);

	paramptr->progvl = argv[3]->value.lval + 1;
	if(argc > 4){
		convert_to_long(argv[4]);
		paramptr->inout = (short)argv[4]->value.lval;
	}else{
		paramptr->inout = 0;
	}

	if((paramptr->progv = (text *)emalloc(paramptr->progvl)) == NULL){		
		php3_error(E_WARNING, "Out of memory for parameter value");
		RETURN_FALSE;
	}

/* XXX Maximum for progvl */
	paramptr->alen = paramptr->progvl;

	if (obndra(&cursor->cda,              
			   argv[2]->value.str.val,
			   -1,
			   (ub1 *)paramptr->progv,
			   paramptr->progvl,
			   SQLT_STR, /* ftype */
			   -1, /* scale */
			   0/*&paramptr->ind*/, /* ind */
			   &paramptr->alen, /* alen */
			   0 /*&paramptr->arcode*/,
			   0, /* maxsize */
			   0,
			   0,
			   -1,
			   -1)) {
		php3_error(E_WARNING, "Ora_Bind failed (%s)",
				   ora_error(&cursor->cda));
		RETURN_FALSE;
	}

	cursor->nparams++;
	RETURN_TRUE;
}
示例#8
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;
			}
	}
}
示例#9
0
/* {{{ proto string ora_columntype(int cursor, int column) 
   Get the type of an Oracle result column */
void php3_Ora_ColumnType(INTERNAL_FUNCTION_PARAMETERS)
{								/* cursor_index, column_index */
	pval *argv[2];
	int cursor_ind, colno;
	oraCursor *cursor = NULL;

	if (ARG_COUNT(ht) != 2 || getParametersArray(ht, 2, argv) == FAILURE) {
		WRONG_PARAM_COUNT;
	}
	convert_to_long(argv[0]);
	/* don't convert the column index yet, it might be the column name */

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

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

	if (cursor->ncols == 0){
		php3_error(E_WARNING, "No tuples available at this cursor index");
		RETURN_FALSE;
	}
        
	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;
	}

	switch (cursor->columns[colno].dbtype) {
		case SQLT_CHR:
			RETURN_STRINGL("VARCHAR2", 8, 1);
		case SQLT_VCS:
	    case SQLT_AVC:
			RETURN_STRINGL("VARCHAR", 7, 1);
		case SQLT_STR:
	    case SQLT_AFC:
			RETURN_STRINGL("CHAR", 4, 1);
		case SQLT_NUM: case SQLT_INT:
		case SQLT_FLT: case SQLT_UIN:
			RETURN_STRINGL("NUMBER", 6, 1);
		case SQLT_LNG:
			RETURN_STRINGL("LONG", 4, 1);
		case SQLT_LBI:
			RETURN_STRINGL("LONG RAW", 8, 1);
		case SQLT_RID:
			RETURN_STRINGL("ROWID", 5, 1);
		case SQLT_DAT:
			RETURN_STRINGL("DATE", 4, 1);
#ifdef SQLT_CUR
		case SQLT_CUR:
			RETURN_STRINGL("CURSOR", 6, 1);
#endif
		default:
		{
			char numbuf[21];
			snprintf(numbuf, 20, "UNKNOWN(%d)", cursor->columns[colno].dbtype);
			numbuf[20] = '\0';
			RETVAL_STRING(numbuf,1);
		}
	}
}
示例#10
0
void orbit_class_function_call(
    zend_class_entry * pClass,
    int dataType,
    zend_property_reference *pPropertyReference,
    Class_Constructor pConstructor,
    Class_CallFunction pCallFunction,
    INTERNAL_FUNCTION_PARAMETERS)
{
    /* get object */
    zval * object = pPropertyReference->object;

    /* get function name */
    zend_overloaded_element * function_name =
        (zend_overloaded_element *)pPropertyReference->elements_list->tail->data;

    /* handle parameters */
    zval ** arguments = orbit_new_n(zval *, ZEND_NUM_ARGS());
    /*(zval **)emalloc(sizeof(zval *) * ZEND_NUM_ARGS());*/
    if (getParametersArray(ht, ZEND_NUM_ARGS(), arguments) == FAILURE)
    {
        /* TODO: handle error */
    }

    /* constructor or normal function? */
    if (zend_llist_count(pPropertyReference->elements_list) == 1
            && !strcasecmp(function_name->element.value.str.val, pClass->name))
    {
        /* constructor */
        if (pConstructor)
        {
            void * p_data = NULL;
            zend_bool success = (*pConstructor)(&p_data, ZEND_NUM_ARGS(), arguments);

            if (success)
                orbit_save_data(object, dataType, p_data);
        }
        else
        {
            zend_error(E_WARNING, "(Satellite) This class has no constructor");
            \
        }
    }
    else
    {
        /* normal function */
        if (pCallFunction)
        {
            void * p_data = orbit_retrieve_data(object, dataType);

            if (p_data == NULL)
            {
                /*
                 * this means that the constructor has failed earlier!
                 * -- or should NULL be allowed here?
                 */
                php_error(E_WARNING, "(Satellite) Class has no data!");
                RETVAL_NULL();
                goto orbit_class_function_call_exit;
            }

            /* pval * return_value is a part of INTERNAL_FUNCTION_PARAMETERS */
            (*pCallFunction)(p_data, function_name->element.value.str.val,
                             ZEND_NUM_ARGS(), arguments, return_value);
        }
        else
        {
            zend_error(E_WARNING, "(Satellite) Can't call functions in this class");
            \
        }
    }

orbit_class_function_call_exit:
    satellite_delete(arguments);

    /* seems to be required! */
    zval_dtor(&function_name->element);
}