summaryrefslogtreecommitdiff
path: root/ext/sqlite/sqlite.c
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2003-05-13 23:51:25 +0000
committerIlia Alshanetsky <iliaa@php.net>2003-05-13 23:51:25 +0000
commitf1c20d3b55e88478ecaa530c33aa380ac36a282e (patch)
treeaa38207f92559ead8129e250387ddb9096474dac /ext/sqlite/sqlite.c
parent0360a2c0122cb0b5cd8012907077bc017a203317 (diff)
downloadphp-git-f1c20d3b55e88478ecaa530c33aa380ac36a282e.tar.gz
Added sqlite_fetch_string(), for speedy fetching of data from database
cursor containing only a single column.
Diffstat (limited to 'ext/sqlite/sqlite.c')
-rw-r--r--ext/sqlite/sqlite.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/ext/sqlite/sqlite.c b/ext/sqlite/sqlite.c
index f3d8d7fc3e..26b1dd8158 100644
--- a/ext/sqlite/sqlite.c
+++ b/ext/sqlite/sqlite.c
@@ -115,6 +115,7 @@ function_entry sqlite_functions[] = {
PHP_FE(sqlite_close, NULL)
PHP_FE(sqlite_query, NULL)
PHP_FE(sqlite_fetch_array, NULL)
+ PHP_FE(sqlite_fetch_string, NULL)
PHP_FE(sqlite_current, NULL)
PHP_FE(sqlite_column, NULL)
PHP_FE(sqlite_libversion, NULL)
@@ -1167,6 +1168,56 @@ PHP_FUNCTION(sqlite_fetch_array)
}
/* }}} */
+/* {{{ proto string sqlite_fetch_array(resource result [, bool decode_binary])
+ Fetches first column of a result set as a string */
+PHP_FUNCTION(sqlite_fetch_string)
+{
+ zval *zres;
+ zend_bool decode_binary = 1;
+ struct php_sqlite_result *res;
+ char *decoded = NULL;
+ int decoded_len;
+ const char **rowdata;
+
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|b", &zres, &decode_binary)) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
+
+ /* check if there are any more rows on the cursor */
+ if (res->curr_row >= res->nrows) {
+ RETURN_FALSE;
+ }
+
+ if (res->buffered) {
+ rowdata = (const char**)&res->table[res->curr_row * res->ncolumns];
+ } else {
+ rowdata = (const char**)res->table;
+ }
+
+ if (decode_binary && rowdata[0] != NULL && rowdata[0][0] == '\x01') {
+ decoded = do_alloca(strlen(rowdata[0]));
+ decoded_len = sqlite_decode_binary(rowdata[0]+1, decoded);
+ } else {
+ decoded = (char*)rowdata[0];
+ decoded_len = decoded ? strlen(decoded) : 0;
+ }
+
+ if (!res->buffered) {
+ /* non buffered: fetch next row */
+ php_sqlite_fetch(res TSRMLS_CC);
+ }
+ /* advance the row pointer */
+ res->curr_row++;
+
+ if (decoded == NULL) {
+ RETURN_NULL();
+ } else {
+ RETURN_STRINGL(decoded, decoded_len, 1);
+ }
+}
+/* }}} */
+
/* {{{ proto array sqlite_fetch_array(resource result [, int result_type, bool decode_binary])
Fetches the current row from a result set as an array */
PHP_FUNCTION(sqlite_current)