cvs: pecl /dbdo dbdo.c

From: Date: Wed, 06 Apr 2005 17:11:50 +0000
Subject: cvs: pecl /dbdo dbdo.c
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-2935@lists.php.net to get a copy of this message
alan_k Wed Apr 6 13:11:50 2005 EDT Modified files: /pecl/dbdo dbdo.c Log: add fetching ability to config http://cvs.php.net/diff.php/pecl/dbdo/dbdo.c?r1=1.83&r2=1.84&ty=u Index: pecl/dbdo/dbdo.c diff -u pecl/dbdo/dbdo.c:1.83 pecl/dbdo/dbdo.c:1.84 --- pecl/dbdo/dbdo.c:1.83 Wed Apr 6 11:31:45 2005 +++ pecl/dbdo/dbdo.c Wed Apr 6 13:11:49 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dbdo.c,v 1.83 2005/04/06 15:31:45 alan_k Exp $ */ +/* $Id: dbdo.c,v 1.84 2005/04/06 17:11:49 alan_k Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -583,7 +583,7 @@ GdaProviderInfo *info; php_info_print_table_start(); php_info_print_table_header(2, "DBDO support", "enabled"); - php_info_print_table_row(2, "CVS id", "$Id: dbdo.c,v 1.83 2005/04/06 15:31:45 alan_k Exp $"); + php_info_print_table_row(2, "CVS id", "$Id: dbdo.c,v 1.84 2005/04/06 17:11:49 alan_k Exp $"); prov_list = gda_config_get_provider_list (); @@ -3175,6 +3175,28 @@ return con; } + +#define DBDO_CONFIG_LEN 7 +static char *dbdo_config_values[] = { + /* 0 */ "require_path", + "class_name", + /* 2 */ "links", + "provider", + /* 4 */ "cnc", + "lowercase_passwords", + /* 6 */ "quote_identifiers" + }; +/* get the id for a specified column */ +int dbdo_config_get_id(char * col) +{ + int i; + for (i=0;i< DBDO_CONFIG_LEN;i++) { + if (!strcasecmp(dbdo_config_values[i],col)) { + return i; + } + } + return -1; +} /* {{{ proto DBDO::config ( $dsn, $key, $value) set any of the config variables.. @@ -3186,74 +3208,118 @@ char *dsn, *key,*value; gboolean bvalue; dbdo_config *con; - int found = 0; + int id = 0; if (zend_parse_parameters(2 TSRMLS_CC, "ss", &dsn, &dsn_len, &key, &key_len) == FAILURE) { RETURN_FALSE; } - /* not amazingly efficient code.. but it should work.. */ - if ((strcmp(key,"require_path") ==0) || - (strcmp(key,"class_name") ==0) || - (strcmp(key,"cnc") ==0) || - (strcmp(key,"provider") ==0) || - (strcmp(key,"links") ==0)) { + id = dbdo_config_get_id(key); + if (id == -1) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid configuration key: %s", key); + RETURN_FALSE; + } + con = dbdo_config_get(dsn TSRMLS_CC); + if (ZEND_NUM_ARGS() == 2) { + if (!con) { + RETURN_FALSE; + } + switch(id) { + case 0: + if (!con->require_path) { + RETURN_FALSE; + } + RETURN_STRING(con->require_path,1); + + case 1: + if (!con->class_name) { + RETURN_FALSE; + } + RETURN_STRING(con->class_name,1); + + case 2: + if (!con->links) { + RETURN_FALSE; + } + RETURN_STRING(con->links,1); + + case 3: + if (!con->provider) { + RETURN_FALSE; + } + RETURN_STRING(con->provider,1) + + case 4: + if (!con->cnc_string) { + RETURN_FALSE; + } + RETURN_STRING(con->cnc_string,1) + + case 5: + RETURN_LONG(con->lowercase_columns); + case 6: + RETURN_LONG(con->quote_identifiers); + } + RETURN_FALSE; /* should not get here! */ + } + /* not amazingly efficient code.. but it should work.. */ + if (id < 5) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &dsn, &dsn_len, &key, &key_len,&value, &value_len) == FAILURE) { RETURN_FALSE; } } else { - if ((strcmp(key,"lowercase_columns") ==0) || - (strcmp(key,"quote_identifiers") ==0)) { - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssi", &dsn, &dsn_len, &key, &key_len,&bvalue) == FAILURE) { - RETURN_FALSE; - } - } else { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid configuration key: %s", key); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssi", &dsn, &dsn_len, &key, &key_len,&bvalue) == FAILURE) { RETURN_FALSE; } - } - - - con = dbdo_config_get(dsn TSRMLS_CC); - if (strcmp(key,"require_path") ==0) { - if (con->require_path) { - efree(con->require_path); - } - con->require_path =estrdup(value); - } - if (strcmp(key,"class_name") ==0) { - if (con->class_name) { - efree(con->class_name); - } - con->class_name = estrdup(value); } - if (strcmp(key,"links") ==0) { - if (con->links) { - efree(con->links); - } - con->links =estrdup(value); - } - if (strcmp(key,"provider") ==0) { - if (con->provider) { - efree(con->provider); - } - con->provider =estrdup(value); - } - if (strcmp(key,"cnc") ==0) { - if (con->cnc_string) { - efree(con->cnc_string); - } - con->cnc_string =estrdup(value); + + switch(id) { + case 0: + if (con->require_path) { + efree(con->require_path); + } + con->require_path =estrdup(value); + break; + + case 1: + if (con->class_name) { + efree(con->class_name); + } + con->class_name = estrdup(value); + break; + case 2: + if (con->links) { + efree(con->links); + } + con->links =estrdup(value); + break; + case 3: + if (con->provider) { + efree(con->provider); + } + con->provider =estrdup(value); + break; + + case 4: + if (con->cnc_string) { + efree(con->cnc_string); + } + con->cnc_string =estrdup(value); + break; + + case 5: + con->lowercase_columns = bvalue; + break; + case 6: + con->quote_identifiers = bvalue; + break; } + + + + - if (strcmp(key,"lowercase_columns") ==0) { - con->lowercase_columns = bvalue; - } - if (strcmp(key,"quote_identifiers") ==0) { - con->quote_identifiers = bvalue; - } RETURN_TRUE; } @@ -3619,51 +3685,4 @@ RETURN_FALSE; } gdav_tmp = gda_value_new_string((const gchar*) str); - ret_str = (char *) gda_connection_value_to_sql_string (obj->con, gdav_tmp); - ZVAL_STRING(return_value, ret_str, 1); - gda_value_free(gdav_tmp); - g_free(ret_str); - -} - - - - - - - - - - -/* {{{ proto $dbdo->__sleep() -writes internal data out.. = borked = use new serialation interface later.. -*/ /* -PHP_METHOD(dbdo, __sleep) -{ - zval *object = getThis(); - zval *rv[DBDO_INFO_LEN]; - int i,key_len; - dbdo_object *obj = zend_object_store_get_object(object TSRMLS_CC); - char *col; - - array_init(return_value); - - for (i=0;i<DBDO_INFO_LEN;i++) { - zval *ztitle, *value; - col = emalloc(strlen(dbdo_info_values[i]) + 2); - sprintf(col, ".%s",dbdo_info_values[i]); - add_next_index_string(return_value, col, 0); - MAKE_STD_ZVAL(ztitle); - ZVAL_STRING(ztitle, col, 0); - value = dbdo_info_get(obj, object, i TSRMLS_CC) ; - std_object_handlers.write_property(object, ztitle, value TSRMLS_CC); - FREE_ZVAL(ztitle); - - } - - -} - - -*/ - + ret_str = (char *) gda_connection_value_to_sq \ No newline at end of file

« previous php.pecl.cvs (#2935) next »