abies           Tue Sep 23 16:58:14 2003 EDT

  Modified files:              
    /php-src/ext/interbase      interbase.c php_interbase.h 
  Log:
  Added ibase_gen_id()
  # Lightweight shortcut to SELECT GEN_ID() ... function
  
Index: php-src/ext/interbase/interbase.c
diff -u php-src/ext/interbase/interbase.c:1.185 php-src/ext/interbase/interbase.c:1.186
--- php-src/ext/interbase/interbase.c:1.185     Mon Sep 22 02:54:29 2003
+++ php-src/ext/interbase/interbase.c   Tue Sep 23 16:58:13 2003
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: interbase.c,v 1.185 2003/09/22 06:54:29 hholzgra Exp $ */
+/* $Id: interbase.c,v 1.186 2003/09/23 20:58:13 abies Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -26,7 +26,7 @@
 
 #include "php.h"
 
-#define FILE_REVISION "$Revision: 1.185 $"
+#define FILE_REVISION "$Revision: 1.186 $"
 
 #if HAVE_IBASE
 
@@ -69,11 +69,11 @@
 #ifdef PHP_WIN32
 #define LL_MASK "I64"
 #define LL_LIT(lit) lit ## I64
-#ifdef FB_SQLDA
-#pragma comment(lib, "fbclient_ms.lib")
-#else
-#pragma comment(lib, "gds32_ms.lib")
-#endif
+#ifdef FB_SQLDA
+#pragma comment(lib, "fbclient_ms.lib")
+#else
+#pragma comment(lib, "gds32_ms.lib")
+#endif
 #else
 #define LL_MASK "ll"
 #define LL_LIT(lit) lit ## ll
@@ -116,7 +116,7 @@
 #if HAVE_STRFTIME
        PHP_FE(ibase_timefmt, NULL)
 #endif
-
+    PHP_FE(ibase_gen_id, NULL)
        PHP_FE(ibase_num_fields, NULL)
        PHP_FE(ibase_num_params, NULL)
 #if abies_0
@@ -728,8 +728,8 @@
        php_info_print_table_row(2, "Interbase Support", "enabled");
 
 #if (SQLDA_CURRENT_VERSION > 1) || defined(FB_SQLDA)
-       isc_get_client_version(tmp);
-       php_info_print_table_row(2, "Client Library", tmp);
+       isc_get_client_version(tmp);
+       php_info_print_table_row(2, "Client Library", tmp);
 #elif (SQL_DIALECT_CURRENT == 1)
        php_info_print_table_row(2, "Client Library", "Interbase 5.6 or earlier");
 #elif !defined(DSC_null)
@@ -4403,6 +4403,113 @@
 }      
 /* }}} */
   
+/* {{{ proto int ibase_gen_id([ resource link_identifier, ] string generator [, int 
increment ])
+   Increments the named generator and returns its new value */
+PHP_FUNCTION(ibase_gen_id)
+{
+       char query[128];
+       
+       zval **arg1, **arg2, **arg3, **query_arg;
+       ibase_db_link *ib_link;
+       ibase_trans *trans = NULL;
+       long increment;
+#ifdef SQL_INT64
+       ISC_INT64 result;
+#else
+       ISC_LONG result;
+#endif
+
+       XSQLDA out_sqlda;
+
+       RESET_ERRMSG;
+
+       switch (ZEND_NUM_ARGS()) {
+               case 1:
+                       if (zend_get_parameters_ex(1, &arg1) == FAILURE) {
+                               RETURN_FALSE;
+                       }
+                       ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, NULL, 
IBG(default_link), "InterBase link", le_link, le_plink);
+                       query_arg = arg1;
+                       increment = 1;
+                       break;
+               case 2:
+                       if (zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
+                               RETURN_FALSE;
+                       }
+
+                       if (Z_TYPE_PP(arg1) == IS_STRING) /* first param is generator, 
second is inc */
+                       {
+                               query_arg = arg1;
+                               convert_to_long_ex(arg2);
+                               increment = Z_LVAL_PP(arg2);
+
+                               ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, NULL, 
IBG(default_link), "InterBase link", le_link, le_plink);
+                       } else {
+                               
_php_ibase_get_link_trans(INTERNAL_FUNCTION_PARAM_PASSTHRU, arg1, &ib_link, &trans);
+                               query_arg = arg2;
+                               increment = 1;
+                       }
+                       break;
+               case 3:
+                       if (zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) 
{
+                               RETURN_FALSE;
+                       }
+                       ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link*, arg1, -1, 
"InterBase link", le_link, le_plink);
+                       
+                       query_arg = arg2;
+                       convert_to_long_ex(arg3);
+                       increment = Z_LVAL_PP(arg3);
+                       
+                       break;                  
+               default:
+                       WRONG_PARAM_COUNT;
+                       break;
+       }
+       
+       convert_to_string_ex(query_arg);
+       sprintf(query, "SELECT GEN_ID(%s,%ld) FROM rdb$database", 
Z_STRVAL_PP(query_arg), increment);
+
+       /* open default transaction */
+       if (_php_ibase_def_trans(ib_link, &trans TSRMLS_CC) == FAILURE) {
+               RETURN_FALSE;
+       }
+       
+       /* allocate a minimal descriptor area */
+       out_sqlda.sqln = out_sqlda.sqld = 1;
+       out_sqlda.version = SQLDA_CURRENT_VERSION;
+       
+       /* allocate the field for the result */
+#ifdef SQL_INT64
+       out_sqlda.sqlvar[0].sqltype = SQL_INT64;
+#else
+       out_sqlda.sqlvar[0].sqltype = SQL_LONG;
+#endif
+       out_sqlda.sqlvar[0].sqlscale = 0;
+       out_sqlda.sqlvar[0].sqllen = sizeof(result);
+       out_sqlda.sqlvar[0].sqldata = (void*) &result;
+
+       /* execute the query */
+       if (isc_dsql_exec_immed2(IB_STATUS, &ib_link->handle, &trans->handle, 0, 
query, SQL_DIALECT_CURRENT, NULL, &out_sqlda))
+       {
+               _php_ibase_error(TSRMLS_C);
+               RETURN_FALSE;
+       }
+
+       /* don't return the generator value as a string unless it doesn't fit in a 
long */
+#ifdef SQL_INT64
+       if (result > LONG_MAX) 
+#endif
+       {
+               char res[24];
+
+               sprintf(res,"%" LL_MASK "d", result);
+               RETURN_STRING(res,1);
+       }
+       RETURN_LONG((long)result);
+}
+
+/* }}} */
+
 #endif /* HAVE_IBASE */
 
 /*
Index: php-src/ext/interbase/php_interbase.h
diff -u php-src/ext/interbase/php_interbase.h:1.61 
php-src/ext/interbase/php_interbase.h:1.62
--- php-src/ext/interbase/php_interbase.h:1.61  Thu Sep  4 17:10:03 2003
+++ php-src/ext/interbase/php_interbase.h       Tue Sep 23 16:58:14 2003
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_interbase.h,v 1.61 2003/09/04 21:10:03 abies Exp $ */
+/* $Id: php_interbase.h,v 1.62 2003/09/23 20:58:14 abies Exp $ */
 
 #ifndef PHP_INTERBASE_H
 #define PHP_INTERBASE_H
@@ -50,7 +50,7 @@
 #if HAVE_STRFTIME
 PHP_FUNCTION(ibase_timefmt);
 #endif
-
+PHP_FUNCTION(ibase_gen_id);
 PHP_FUNCTION(ibase_num_fields);
 PHP_FUNCTION(ibase_num_params);
 #if abies_0

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to