summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank M. Kromann <fmk@php.net>2001-06-28 16:59:17 +0000
committerFrank M. Kromann <fmk@php.net>2001-06-28 16:59:17 +0000
commita98efcda7693a9899166c91113ce9888ad9dd9cf (patch)
treec5fd4cb4145ba0e0accb092f8e71af71f232f467
parent5884ff34128153ed0f2ecaed69c1a9fee5208887 (diff)
downloadphp-git-a98efcda7693a9899166c91113ce9888ad9dd9cf.tar.gz
Adding new function to convert from binary to GUID format
-rw-r--r--ext/mssql/php_mssql.c74
-rw-r--r--ext/mssql/php_mssql.h3
2 files changed, 74 insertions, 3 deletions
diff --git a/ext/mssql/php_mssql.c b/ext/mssql/php_mssql.c
index 68cd61fe4d..967238be61 100644
--- a/ext/mssql/php_mssql.c
+++ b/ext/mssql/php_mssql.c
@@ -12,7 +12,7 @@
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
- | Authors: Frank M. Kromann frank@frontbase.com> |
+ | Authors: Frank M. Kromann <frank@frontbase.com> |
+----------------------------------------------------------------------+
*/
@@ -76,6 +76,7 @@ function_entry mssql_functions[] = {
PHP_FE(mssql_init, NULL)
PHP_FE(mssql_bind, a3_arg_force_ref)
PHP_FE(mssql_execute, NULL)
+ PHP_FE(mssql_guid_string, NULL)
{NULL, NULL, NULL}
};
@@ -775,7 +776,7 @@ static void php_mssql_get_column_content_with_type(mssql_link *mssql_ptr,int off
result->value.lval = (long) anyintcol(offset);
result->type = IS_LONG;
break;
- }
+ }
case SQLCHAR:
case SQLVARCHAR:
case SQLTEXT: {
@@ -2125,4 +2126,73 @@ PHP_FUNCTION(mssql_execute)
}
/* }}} */
+/* {{{ proto string mssql_guid_string(string binary [,int short_format])
+ Converts a 16 byte binary GUID to a string */
+PHP_FUNCTION(mssql_guid_string)
+{
+ zval **binary, **short_format;
+ int sf = 0;
+ char buffer[32+1];
+ char buffer2[36+1];
+ MSSQLLS_FETCH();
+
+ switch(ZEND_NUM_ARGS()) {
+ case 1:
+ if (zend_get_parameters_ex(1, &binary)==FAILURE) {
+ RETURN_FALSE;
+ }
+ convert_to_string_ex(binary);
+ break;
+ case 2:
+ if (zend_get_parameters_ex(2, &binary, &short_format)==FAILURE) {
+ RETURN_FALSE;
+ }
+ convert_to_string_ex(binary);
+ convert_to_long_ex(short_format);
+ sf = (*short_format)->value.lval;
+ break;
+
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+
+ dbconvert(NULL, SQLBINARY, (BYTE*)(*binary)->value.str.val, 16, SQLCHAR, buffer, -1);
+
+ if (sf) {
+ php_strtoupper(buffer, 32);
+ RETURN_STRING(buffer, 1);
+ }
+ else {
+ int i;
+ for (i=0; i<4; i++) {
+ buffer2[2*i] = buffer[6-2*i];
+ buffer2[2*i+1] = buffer[7-2*i];
+ }
+ buffer2[8] = '-';
+ for (i=0; i<2; i++) {
+ buffer2[9+2*i] = buffer[10-2*i];
+ buffer2[10+2*i] = buffer[11-2*i];
+ }
+ buffer2[13] = '-';
+ for (i=0; i<2; i++) {
+ buffer2[14+2*i] = buffer[14-2*i];
+ buffer2[15+2*i] = buffer[15-2*i];
+ }
+ buffer2[18] = '-';
+ for (i=0; i<4; i++) {
+ buffer2[19+i] = buffer[16+i];
+ }
+ buffer2[23] = '-';
+ for (i=0; i<12; i++) {
+ buffer2[24+i] = buffer[20+i];
+ }
+ buffer2[36] = 0;
+
+ php_strtoupper(buffer2, 36);
+ RETURN_STRING(buffer2, 1);
+ }
+}
+/* }}} */
+
#endif
diff --git a/ext/mssql/php_mssql.h b/ext/mssql/php_mssql.h
index 4fab922cd1..f3b0dc2563 100644
--- a/ext/mssql/php_mssql.h
+++ b/ext/mssql/php_mssql.h
@@ -12,7 +12,7 @@
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
- | Authors: Frank M. Kromann frank@frontbase.com> |
+ | Authors: Frank M. Kromann <frank@frontbase.com> |
+----------------------------------------------------------------------+
*/
@@ -83,6 +83,7 @@ PHP_FUNCTION(mssql_min_message_severity);
PHP_FUNCTION(mssql_init);
PHP_FUNCTION(mssql_bind);
PHP_FUNCTION(mssql_execute);
+PHP_FUNCTION(mssql_guid_string);
typedef struct mssql_link {
LOGINREC *login;