summaryrefslogtreecommitdiff
path: root/ext/fbsql
diff options
context:
space:
mode:
authorFrank M. Kromann <fmk@php.net>2001-10-10 00:42:00 +0000
committerFrank M. Kromann <fmk@php.net>2001-10-10 00:42:00 +0000
commitffd40bf495849c3eac967b31df54882cd0c49b63 (patch)
tree7daaf5885863e0dc1b082cecb9e17e3825d976fb /ext/fbsql
parent70a60c43ab386da8038d77cd14fa1f0ae2ec8b12 (diff)
downloadphp-git-ffd40bf495849c3eac967b31df54882cd0c49b63.tar.gz
Adding support for BLOB and CLOB
Diffstat (limited to 'ext/fbsql')
-rw-r--r--ext/fbsql/php_fbsql.c120
-rw-r--r--ext/fbsql/php_fbsql.h4
2 files changed, 98 insertions, 26 deletions
diff --git a/ext/fbsql/php_fbsql.c b/ext/fbsql/php_fbsql.c
index 8c9e2fd230..221da1f9cd 100644
--- a/ext/fbsql/php_fbsql.c
+++ b/ext/fbsql/php_fbsql.c
@@ -24,7 +24,6 @@
*/
/* SB's list:
- - BLOBs
- API for a more natural FB connect semantic
- Connect & set session
- Autoreconnect when disconnected
@@ -64,7 +63,7 @@
#include "php_fbsql.h"
#include <signal.h>
-static int le_result, le_link, le_plink;
+static int le_result, le_link, le_plink, le_lob;
struct PHPFBResult;
typedef struct PHPFBResult PHPFBResult;
@@ -211,6 +210,9 @@ function_entry fbsql_functions[] = {
PHP_FE(fbsql_commit, NULL)
PHP_FE(fbsql_rollback, NULL)
+ PHP_FE(fbsql_create_blob, NULL)
+ PHP_FE(fbsql_create_clob, NULL)
+
PHP_FE(fbsql_hostname, NULL)
PHP_FE(fbsql_database, NULL)
PHP_FE(fbsql_database_password, NULL)
@@ -250,6 +252,7 @@ ZEND_GET_MODULE(fbsql)
static void phpfbReleaseResult (zend_rsrc_list_entry *rsrc TSRMLS_DC);
static void phpfbReleaseLink (zend_rsrc_list_entry *rsrc TSRMLS_DC);
static void phpfbReleasePLink (zend_rsrc_list_entry *rsrc TSRMLS_DC);
+static void phpfbReleaseLOB (zend_rsrc_list_entry *rsrc TSRMLS_DC);
static void phpfbReleaseResult(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
@@ -315,6 +318,16 @@ static void phpfbReleasePLink(zend_rsrc_list_entry *rsrc TSRMLS_DC)
}
}
+static void phpfbReleaseLOB(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+{
+ FBCBlobHandle *lobHandle = (FBCBlobHandle *)rsrc->ptr;
+
+ if (lobHandle)
+ {
+ fbcbhRelease(lobHandle);
+ }
+}
+
static void php_fbsql_set_default_link(int id TSRMLS_DC)
{
if (FB_SQL_G(linkIndex)!=-1) {
@@ -379,9 +392,10 @@ PHP_MINIT_FUNCTION(fbsql)
fbcInitialize();
- le_result = zend_register_list_destructors_ex(phpfbReleaseResult, NULL, "fbsql result", module_number);
- le_link = zend_register_list_destructors_ex(phpfbReleaseLink, NULL, "fbsql link", module_number);
- le_plink = zend_register_list_destructors_ex(NULL, phpfbReleasePLink, "fbsql plink", module_number);
+ le_result = zend_register_list_destructors_ex(phpfbReleaseResult, NULL, "fbsql result", module_number);
+ le_link = zend_register_list_destructors_ex(phpfbReleaseLink, NULL, "fbsql link", module_number);
+ le_plink = zend_register_list_destructors_ex(NULL, phpfbReleasePLink, "fbsql plink", module_number);
+ le_lob = zend_register_list_destructors_ex(phpfbReleaseLOB, NULL, "fbsql lob handle", module_number);
Z_TYPE(fbsql_module_entry) = type;
REGISTER_LONG_CONSTANT("FBSQL_ASSOC", FBSQL_ASSOC, CONST_CS | CONST_PERSISTENT);
@@ -900,6 +914,61 @@ PHP_FUNCTION(fbsql_rollback)
}
/* }}} */
+
+static void php_fbsql_create_lob(INTERNAL_FUNCTION_PARAMETERS, int lob_type)
+{
+ PHPFBLink* phpLink = NULL;
+ FBCBlobHandle *lobHandle;
+ zval **lob_data, **fbsql_link_index = NULL;
+ int id;
+
+ switch (ZEND_NUM_ARGS()) {
+ case 1:
+ if (zend_get_parameters_ex(1, &lob_data)==FAILURE) {
+ RETURN_FALSE;
+ }
+ id = php_fbsql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(id);
+ break;
+ case 2:
+ if (zend_get_parameters_ex(2, &lob_data, &fbsql_link_index)==FAILURE) {
+ RETURN_FALSE;
+ }
+ id = -1;
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+ ZEND_FETCH_RESOURCE2(phpLink, PHPFBLink *, fbsql_link_index, id, "FrontBase-Link", le_link, le_plink);
+
+ switch (lob_type) {
+ case 0 : // BLOB
+ lobHandle = fbcdcWriteBLOB(phpLink->connection, Z_STRVAL_PP(lob_data), Z_STRLEN_PP(lob_data));
+ break;
+ case 1 : // CLOB
+ lobHandle = fbcdcWriteCLOB(phpLink->connection, Z_STRVAL_PP(lob_data));
+ break;
+ }
+ ZEND_REGISTER_RESOURCE(return_value, lobHandle, le_lob);
+}
+
+/* {{{ proto resource fbsql_create_blob(string blob_data [, resource link_identifier])
+ */
+PHP_FUNCTION(fbsql_create_blob)
+{
+ php_fbsql_create_lob(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
+}
+/* }}} */
+
+/* {{{ proto resource fbsql_create_clob(string clob_data [, resource link_identifier])
+ */
+PHP_FUNCTION(fbsql_create_clob)
+{
+ php_fbsql_create_lob(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
+}
+/* }}} */
+
/* {{{ proto string fbsql_hostname(resource link_identifier [, string host_name])
*/
PHP_FUNCTION(fbsql_hostname)
@@ -2131,33 +2200,32 @@ void phpfbColumnAsString (PHPFBResult* result, int column, void* data , int* len
case FB_CLOB:
case FB_BLOB:
-/* {
- unsigned char* bytes = (unsigned char*)data;
- if (*bytes == '\1')
- { /* Direct
- unsigned int l = *((unsigned int*)(bytes+1));
- unsigned char* ptr = *((unsigned char**)(bytes+5));
- unsigned int i;
- mf(file, "%4d:", l);
- for (i=0; i < l; i++)
- {
- if (i)
- {
- if ((i % 32) == 0)
- mf(file, "\n %*d:", lw+4, i);
- else if ((i % 4) == 0)
- mf(file, " ");
- }
- mf(file, "%02x", *ptr++);
- }
+ {
+ if (*((unsigned char*) data) == '\1')
+ { // Direct
+ *length = ((FBCBlobDirect *)data)->blobSize;
+
+ *value = emalloc(*length + 1);
+ strncpy(*value, (char *)((FBCBlobDirect *)data)->blobData, *length);
}
else
{
- mf(file, "%s", bytes+1);
+ FBCBlobHandle *lobHandle;
+ char *handle = (char *)(&((unsigned char*)data)[1]);
+
+ lobHandle = fbcbhInitWithHandle(handle);
+ *length = fbcbhBlobSize(lobHandle);
+
+ *value = emalloc(*length + 1);
+ if (dtc == FB_BLOB)
+ strncpy(*value, (char *)fbcdcReadBLOB(result->link->connection, lobHandle), *length);
+ else
+ strncpy(*value, (char *)fbcdcReadCLOB(result->link->connection, lobHandle), *length);
+ fbcbhRelease(lobHandle);
}
}
break;
-*/
+
default:
php_error(E_WARNING, "Unimplemented type");
break;
diff --git a/ext/fbsql/php_fbsql.h b/ext/fbsql/php_fbsql.h
index 7f6d0a6b56..a270a6a067 100644
--- a/ext/fbsql/php_fbsql.h
+++ b/ext/fbsql/php_fbsql.h
@@ -80,6 +80,10 @@ PHP_FUNCTION(fbsql_set_transaction);
PHP_FUNCTION(fbsql_autocommit);
PHP_FUNCTION(fbsql_commit);
PHP_FUNCTION(fbsql_rollback);
+
+PHP_FUNCTION(fbsql_create_blob);
+PHP_FUNCTION(fbsql_create_clob);
+
PHP_FUNCTION(fbsql_hostname);
PHP_FUNCTION(fbsql_database);
PHP_FUNCTION(fbsql_database_password);