iliaa Thu Dec 18 16:28:01 2003 EDT Added files: /php-src/ext/sqlite/tests sqlite_026.phpt sqlite_oo_028.phpt
Modified files: /php-src NEWS /php-src/ext/sqlite php_sqlite.h sqlite.c Log: Added sqlite_fetch_column_types() function. Index: php-src/NEWS diff -u php-src/NEWS:1.1546 php-src/NEWS:1.1547 --- php-src/NEWS:1.1546 Thu Dec 18 15:25:19 2003 +++ php-src/NEWS Thu Dec 18 16:27:59 2003 @@ -29,6 +29,7 @@ . stream_socket_sendto() and stream_socket_recvfrom(). (Wez) . iconv_mime_decode_headers(). (Moriyoshi) . get_declared_interfaces(). (Andrey, Marcus) + . sqlite_fetch_column_types(). (Ilia) - Added proxy support to http:// wrapper. (Sara) - Added rename(), rmdir() and mkdir() support to userstreams. (Sara) - Added rename(), rmdir() and mkdir() support to ftp:// wrapper. (Sara) Index: php-src/ext/sqlite/php_sqlite.h diff -u php-src/ext/sqlite/php_sqlite.h:1.26 php-src/ext/sqlite/php_sqlite.h:1.27 --- php-src/ext/sqlite/php_sqlite.h:1.26 Thu Aug 28 19:19:51 2003 +++ php-src/ext/sqlite/php_sqlite.h Thu Dec 18 16:28:00 2003 @@ -17,7 +17,7 @@ | Marcus Boerger <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: php_sqlite.h,v 1.26 2003/08/28 23:19:51 helly Exp $ + $Id: php_sqlite.h,v 1.27 2003/12/18 21:28:00 iliaa Exp $ */ #ifndef PHP_SQLITE_H @@ -88,6 +88,8 @@ PHP_FUNCTION(sqlite_factory); +PHP_FUNCTION(sqlite_fetch_column_types); + ZEND_BEGIN_MODULE_GLOBALS(sqlite) int assoc_case; ZEND_END_MODULE_GLOBALS(sqlite) Index: php-src/ext/sqlite/sqlite.c diff -u php-src/ext/sqlite/sqlite.c:1.104 php-src/ext/sqlite/sqlite.c:1.105 --- php-src/ext/sqlite/sqlite.c:1.104 Sun Dec 14 13:45:36 2003 +++ php-src/ext/sqlite/sqlite.c Thu Dec 18 16:28:00 2003 @@ -17,7 +17,7 @@ | Marcus Boerger <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: sqlite.c,v 1.104 2003/12/14 18:45:36 iliaa Exp $ + $Id: sqlite.c,v 1.105 2003/12/18 21:28:00 iliaa Exp $ */ #ifdef HAVE_CONFIG_H @@ -192,6 +192,7 @@ PHP_FE(sqlite_factory, third_arg_force_ref) PHP_FE(sqlite_udf_encode_binary, NULL) PHP_FE(sqlite_udf_decode_binary, NULL) + PHP_FE(sqlite_fetch_column_types, NULL) {NULL, NULL, NULL} }; @@ -211,6 +212,7 @@ PHP_ME_MAPPING(create_function, sqlite_create_function, NULL) PHP_ME_MAPPING(busy_timeout, sqlite_busy_timeout, NULL) PHP_ME_MAPPING(last_error, sqlite_last_error, NULL) + PHP_ME_MAPPING(fetch_column_types, sqlite_fetch_column_types, NULL) /* PHP_ME_MAPPING(error_string, sqlite_error_string, NULL) static */ /* PHP_ME_MAPPING(escape_string, sqlite_escape_string, NULL) static */ {NULL, NULL, NULL} @@ -1071,7 +1073,7 @@ { php_info_print_table_start(); php_info_print_table_header(2, "SQLite support", "enabled"); - php_info_print_table_row(2, "PECL Module version", PHP_SQLITE_MODULE_VERSION " $Id: sqlite.c,v 1.104 2003/12/14 18:45:36 iliaa Exp $"); + php_info_print_table_row(2, "PECL Module version", PHP_SQLITE_MODULE_VERSION " $Id: sqlite.c,v 1.105 2003/12/18 21:28:00 iliaa Exp $"); php_info_print_table_row(2, "SQLite Library", sqlite_libversion()); php_info_print_table_row(2, "SQLite Encoding", sqlite_libencoding()); php_info_print_table_end(); @@ -1552,6 +1554,72 @@ } /* }}} */ +/* {{{ proto resource sqlite_fetch_column_types(string table_name, resource db) + Return an array of column types from a particular table. */ +PHP_FUNCTION(sqlite_fetch_column_types) +{ + zval *zdb; + struct php_sqlite_db *db; + char *tbl, *sql; + long tbl_len; + char *errtext = NULL; + zval *object = getThis(); + struct php_sqlite_result res; + const char **rowdata, **colnames, *tail; + int i, ncols; + + if (object) { + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &tbl, &tbl_len)) { + return; + } + DB_FROM_OBJECT(db, object); + } else { + if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, + ZEND_NUM_ARGS() TSRMLS_CC, "sr", &tbl, &tbl_len, &zdb) && + FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &zdb, &tbl, &tbl_len)) { + return; + } + DB_FROM_ZVAL(db, &zdb); + } + + if (!(sql = sqlite_mprintf("SELECT * FROM %q LIMIT 1", tbl))) { + RETURN_FALSE; + } + + sqlite_exec(db->db, "PRAGMA show_datatypes = ON", NULL, NULL, &errtext); + + db->last_err_code = sqlite_compile(db->db, sql, &tail, &res.vm, &errtext); + + sqlite_freemem(sql); + + if (db->last_err_code != SQLITE_OK) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", errtext); + sqlite_freemem(errtext); + RETVAL_FALSE; + goto done; + } + + sqlite_step(res.vm, &ncols, &rowdata, &colnames); + + array_init(return_value); + + for (i = 0; i < ncols; i++) { + char *colname = (char *)colnames[i]; + + if (SQLITE_G(assoc_case) == 1) { + php_sqlite_strtoupper(colname); + } else if (SQLITE_G(assoc_case) == 2) { + php_sqlite_strtolower(colname); + } + + add_assoc_string(return_value, colname, colnames[ncols + i] ? (char *)colnames[ncols + i] : "", 1); + } + +done: + sqlite_exec(db->db, "PRAGMA show_datatypes = OFF", NULL, NULL, &errtext); +} +/* }}} */ + /* {{{ proto resource sqlite_query(string query, resource db [, int result_type ]) Executes a query against a given database and returns a result handle. */ PHP_FUNCTION(sqlite_query) Index: php-src/ext/sqlite/tests/sqlite_026.phpt +++ php-src/ext/sqlite/tests/sqlite_026.phpt --TEST-- sqlite: sqlite_fetch_column_types --SKIPIF-- <?php # vim:ft=php if (!extension_loaded("sqlite")) print "skip"; ?> --FILE-- <?php include "blankdb.inc"; sqlite_query($db, "CREATE TABLE strings(a, b INTEGER, c VARCHAR(10), d)"); sqlite_query($db, "INSERT INTO strings VALUES('1', '2', '3', 'abc')"); var_dump(sqlite_fetch_column_types($db, "strings")); sqlite_close($db); ?> --EXPECT-- array(4) { ["a"]=> string(0) "" ["b"]=> string(7) "INTEGER" ["c"]=> string(11) "VARCHAR(10)" ["d"]=> string(0) "" } Index: php-src/ext/sqlite/tests/sqlite_oo_028.phpt +++ php-src/ext/sqlite/tests/sqlite_oo_028.phpt --TEST-- sqlite-oo: sqlite_fetch_column_types --SKIPIF-- <?php # vim:ft=php if (!extension_loaded("sqlite")) print "skip"; ?> --FILE-- <?php include "blankdb_oo.inc"; $db->query("CREATE TABLE strings(a, b INTEGER, c VARCHAR(10), d)"); $db->query("INSERT INTO strings VALUES('1', '2', '3', 'abc')"); var_dump($db->fetch_column_types("strings")); ?> --EXPECT-- array(4) { ["a"]=> string(0) "" ["b"]=> string(7) "INTEGER" ["c"]=> string(11) "VARCHAR(10)" ["d"]=> string(0) "" } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php