fix issue #19: Failed test with PgSQL < 9.3 fix-19 33/head
authorMichael Wallner <mike@php.net>
Tue, 18 Jun 2019 10:02:30 +0000 (12:02 +0200)
committerMichael Wallner <mike@php.net>
Tue, 18 Jun 2019 10:02:30 +0000 (12:02 +0200)
src/php_pqres.c

index 849f8bff65f22cbdc3ef2f42e9a511e227c992d1..3427b383414ab39d7d430adb0174850aac00229e 100644 (file)
@@ -491,65 +491,83 @@ static void php_pqres_object_read_error_message(zval *object, void *o, zval *ret
        }
 }
 
-static void php_pqres_object_read_diag(zval *object, void *o, zval *return_value)
-{
-       php_pqres_object_t *obj = o;
-       int i;
-       struct {
-               char code;
-               const char *const name;
-       } diag[] = {
-#ifdef PG_DIAG_SEVERITY
-                       {PG_DIAG_SEVERITY,                      "severity"},
+#ifndef PG_DIAG_SEVERITY
+# define PG_DIAG_SEVERITY 'S'
 #endif
-#ifdef PG_DIAG_SQLSTATE
-                       {PG_DIAG_SQLSTATE,                      "sqlstate"},
+#ifndef PG_DIAG_SQLSTATE
+# define PG_DIAG_SQLSTATE 'C'
 #endif
-#ifdef PG_DIAG_MESSAGE_PRIMARY
-                       {PG_DIAG_MESSAGE_PRIMARY,       "message_primary"},
+#ifndef PG_DIAG_MESSAGE_PRIMARY
+# define PG_DIAG_MESSAGE_PRIMARY 'M'
 #endif
-#ifdef PG_DIAG_MESSAGE_DETAIL
-                       {PG_DIAG_MESSAGE_DETAIL,        "message_detail"},
+#ifndef PG_DIAG_MESSAGE_DETAIL
+# define PG_DIAG_MESSAGE_DETAIL 'D'
 #endif
-#ifdef PG_DIAG_MESSAGE_HINT
-                       {PG_DIAG_MESSAGE_HINT,          "message_hint"},
+#ifndef PG_DIAG_MESSAGE_HINT
+# define PG_DIAG_MESSAGE_HINT 'H'
 #endif
-#ifdef PG_DIAG_STATEMENT_POSITION
-                       {PG_DIAG_STATEMENT_POSITION,"statement_position"},
+#ifndef PG_DIAG_STATEMENT_POSITION
+# define PG_DIAG_STATEMENT_POSITION 'P'
 #endif
-#ifdef PG_DIAG_INTERNAL_POSITION
-                       {PG_DIAG_INTERNAL_POSITION,     "internal_position"},
+#ifndef PG_DIAG_INTERNAL_POSITION
+# define PG_DIAG_INTERNAL_POSITION 'p'
 #endif
-#ifdef PG_DIAG_INTERNAL_QUERY
-                       {PG_DIAG_INTERNAL_QUERY,        "internal_query"},
+#ifndef PG_DIAG_INTERNAL_QUERY
+# define PG_DIAG_INTERNAL_QUERY 'q'
 #endif
-#ifdef PG_DIAG_CONTEXT
-                       {PG_DIAG_CONTEXT,                       "context"},
+#ifndef PG_DIAG_CONTEXT
+# define PG_DIAG_CONTEXT 'W'
 #endif
-#ifdef PG_DIAG_SCHEMA_NAME
-                       {PG_DIAG_SCHEMA_NAME,           "schema_name"},
+#ifndef PG_DIAG_SCHEMA_NAME
+# define PG_DIAG_SCHEMA_NAME 's'
 #endif
-#ifdef PG_DIAG_TABLE_NAME
-                       {PG_DIAG_TABLE_NAME,            "table_name"},
+#ifndef PG_DIAG_TABLE_NAME
+# define PG_DIAG_TABLE_NAME 't'
 #endif
-#ifdef PG_DIAG_COLUMN_NAME
-                       {PG_DIAG_COLUMN_NAME,           "column_name"},
+#ifndef PG_DIAG_COLUMN_NAME
+# define PG_DIAG_COLUMN_NAME 'c'
 #endif
-#ifdef PG_DIAG_DATATYPE_NAME
-                       {PG_DIAG_DATATYPE_NAME,         "datatype_name"},
+#ifndef PG_DIAG_DATATYPE_NAME
+# define PG_DIAG_DATATYPE_NAME 'd'
 #endif
-#ifdef PG_DIAG_CONSTRAINT_NAME
-                       {PG_DIAG_CONSTRAINT_NAME,       "constraint_name"},
+#ifndef PG_DIAG_CONSTRAINT_NAME
+# define PG_DIAG_CONSTRAINT_NAME 'n'
 #endif
-#ifdef PG_DIAG_SOURCE_FILE
-                       {PG_DIAG_SOURCE_FILE,           "source_file"},
+#ifndef PG_DIAG_SOURCE_FILE
+# define PG_DIAG_SOURCE_FILE 'F'
 #endif
-#ifdef PG_DIAG_SOURCE_LINE
-                       {PG_DIAG_SOURCE_LINE,           "source_line"},
+#ifndef PG_DIAG_SOURCE_LINE
+# define PG_DIAG_SOURCE_LINE 'L'
 #endif
-#ifdef PG_DIAG_SOURCE_FUNCTION
-                       {PG_DIAG_SOURCE_FUNCTION,       "source_function"},
+#ifndef PG_DIAG_SOURCE_FUNCTION
+# define PG_DIAG_SOURCE_FUNCTION 'R'
 #endif
+
+static void php_pqres_object_read_diag(zval *object, void *o, zval *return_value)
+{
+       php_pqres_object_t *obj = o;
+       int i;
+       struct {
+               char code;
+               const char *const name;
+       } diag[] = {
+               {PG_DIAG_SEVERITY,                      "severity"},
+               {PG_DIAG_SQLSTATE,                      "sqlstate"},
+               {PG_DIAG_MESSAGE_PRIMARY,       "message_primary"},
+               {PG_DIAG_MESSAGE_DETAIL,        "message_detail"},
+               {PG_DIAG_MESSAGE_HINT,          "message_hint"},
+               {PG_DIAG_STATEMENT_POSITION,"statement_position"},
+               {PG_DIAG_INTERNAL_POSITION,     "internal_position"},
+               {PG_DIAG_INTERNAL_QUERY,        "internal_query"},
+               {PG_DIAG_CONTEXT,                       "context"},
+               {PG_DIAG_SCHEMA_NAME,           "schema_name"},
+               {PG_DIAG_TABLE_NAME,            "table_name"},
+               {PG_DIAG_COLUMN_NAME,           "column_name"},
+               {PG_DIAG_DATATYPE_NAME,         "datatype_name"},
+               {PG_DIAG_CONSTRAINT_NAME,       "constraint_name"},
+               {PG_DIAG_SOURCE_FILE,           "source_file"},
+               {PG_DIAG_SOURCE_LINE,           "source_line"},
+               {PG_DIAG_SOURCE_FUNCTION,       "source_function"},
        };
 
        array_init_size(return_value, 32);