summaryrefslogtreecommitdiff
path: root/ext/sqlite/sqlite.c
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2003-06-21 12:29:32 +0000
committerWez Furlong <wez@php.net>2003-06-21 12:29:32 +0000
commit9e858102a8acbdb78c568d58a5206498d25c9163 (patch)
tree6e908989a7928b26bc5b65fafc6639c84fc165d5 /ext/sqlite/sqlite.c
parent418e4aee58a34d11589d99c2c260e3aa88eb4081 (diff)
downloadphp-git-9e858102a8acbdb78c568d58a5206498d25c9163.tar.gz
Add a pair of functions to handle the binary coding used by PHP from within
UDF callbacks. Add test for binary functions. Fix proto.
Diffstat (limited to 'ext/sqlite/sqlite.c')
-rw-r--r--ext/sqlite/sqlite.c65
1 files changed, 63 insertions, 2 deletions
diff --git a/ext/sqlite/sqlite.c b/ext/sqlite/sqlite.c
index 49cdceb73c..416fab2a94 100644
--- a/ext/sqlite/sqlite.c
+++ b/ext/sqlite/sqlite.c
@@ -142,6 +142,8 @@ function_entry sqlite_functions[] = {
PHP_FE(sqlite_unbuffered_query, NULL)
PHP_FE(sqlite_create_aggregate, NULL)
PHP_FE(sqlite_create_function, NULL)
+ PHP_FE(sqlite_udf_encode_binary, NULL)
+ PHP_FE(sqlite_udf_decode_binary, NULL)
{NULL, NULL, NULL}
};
@@ -1371,8 +1373,8 @@ PHP_FUNCTION(sqlite_current)
}
/* }}} */
-/* {{{ proto array sqlite_column(resource result, mixed index_or_name [, bool decode_binary])
- Fetches a column from the current row from a result set */
+/* {{{ proto mixed sqlite_column(resource result, mixed index_or_name [, bool decode_binary])
+ Fetches a column from the current row of a result set */
PHP_FUNCTION(sqlite_column)
{
zval *zres;
@@ -1808,6 +1810,65 @@ PHP_FUNCTION(sqlite_create_function)
}
/* }}} */
+/* {{{ proto string sqlite_udf_encode_binary(string data)
+ Apply binary encoding (if required) to a string to return from an UDF */
+PHP_FUNCTION(sqlite_udf_encode_binary)
+{
+ char *data = NULL;
+ long datalen;
+
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &data, &datalen)) {
+ return;
+ }
+
+ if (data == NULL) {
+ RETURN_NULL();
+ }
+ if (datalen && (data[0] == '\x01' || memchr(data, '\0', datalen) != NULL)) {
+ /* binary string */
+ int enclen;
+ char *ret;
+
+ ret = emalloc( 1 + ((256 * datalen + 1262) / 253) );
+ ret[0] = '\x01';
+ enclen = sqlite_encode_binary((const unsigned char*)data, datalen, ret+1);
+ RETVAL_STRINGL(ret, enclen+1, 0);
+ } else {
+ RETVAL_STRINGL(data, datalen, 1);
+ }
+}
+/* }}} */
+
+/* {{{ proto string sqlite_udf_decode_binary(string data)
+ Decode binary encoding on a string parameter passed to an UDF */
+PHP_FUNCTION(sqlite_udf_decode_binary)
+{
+ char *data = NULL;
+ long datalen;
+
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &data, &datalen)) {
+ return;
+ }
+
+ if (data == NULL) {
+ RETURN_NULL();
+ }
+ if (datalen && data[0] == '\x01') {
+ /* encoded string */
+ int enclen;
+ char *ret;
+
+ ret = emalloc(datalen);
+ enclen = sqlite_decode_binary((const unsigned char*)data+1, ret);
+ ret[enclen] = '\0';
+ RETVAL_STRINGL(ret, enclen, 0);
+ } else {
+ RETVAL_STRINGL(data, datalen, 1);
+ }
+}
+/* }}} */
+
+
/*
* Local variables:
* tab-width: 4