]> granicus.if.org Git - postgresql/commitdiff
Let compiler handle size calculation of bool types.
authorMichael Meskes <meskes@postgresql.org>
Thu, 17 Sep 2015 13:41:04 +0000 (15:41 +0200)
committerMichael Meskes <meskes@postgresql.org>
Thu, 17 Sep 2015 13:42:46 +0000 (15:42 +0200)
Back in the day this did not work, but modern compilers should handle it themselves.

src/interfaces/ecpg/ecpglib/data.c
src/interfaces/ecpg/ecpglib/execute.c

index 8d36484f73aa280d07a822126bf14715220ee00d..82ab4aaf868853cce9c97ed7ef16f1f567547d3c 100644 (file)
@@ -423,27 +423,13 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
                                case ECPGt_bool:
                                        if (pval[0] == 'f' && pval[1] == '\0')
                                        {
-                                               if (offset == sizeof(char))
-                                                       *((char *) (var + offset * act_tuple)) = false;
-                                               else if (offset == sizeof(int))
-                                                       *((int *) (var + offset * act_tuple)) = false;
-                                               else
-                                                       ecpg_raise(lineno, ECPG_CONVERT_BOOL,
-                                                                          ECPG_SQLSTATE_DATATYPE_MISMATCH,
-                                                                          NULL);
+                                               *((bool *) (var + offset * act_tuple)) = false;
                                                pval++;
                                                break;
                                        }
                                        else if (pval[0] == 't' && pval[1] == '\0')
                                        {
-                                               if (offset == sizeof(char))
-                                                       *((char *) (var + offset * act_tuple)) = true;
-                                               else if (offset == sizeof(int))
-                                                       *((int *) (var + offset * act_tuple)) = true;
-                                               else
-                                                       ecpg_raise(lineno, ECPG_CONVERT_BOOL,
-                                                                          ECPG_SQLSTATE_DATATYPE_MISMATCH,
-                                                                          NULL);
+                                               *((bool *) (var + offset * act_tuple)) = true;
                                                pval++;
                                                break;
                                        }
index 9e40f4161a5923b1912b4934d8e037b435eeb8e1..3b6eedb03b757482333b700fd632de92d314af6f 100644 (file)
@@ -752,18 +752,9 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
                                {
                                        strcpy(mallocedval, "{");
 
-                                       if (var->offset == sizeof(char))
-                                               for (element = 0; element < asize; element++)
-                                                       sprintf(mallocedval + strlen(mallocedval), "%c,", (((char *) var->value)[element]) ? 't' : 'f');
+                                       for (element = 0; element < asize; element++)
+                                                        sprintf(mallocedval + strlen(mallocedval), "%c,", (((bool *) var->value)[element]) ? 't' : 'f');
 
-                                       /*
-                                        * this is necessary since sizeof(C++'s bool)==sizeof(int)
-                                        */
-                                       else if (var->offset == sizeof(int))
-                                               for (element = 0; element < asize; element++)
-                                                       sprintf(mallocedval + strlen(mallocedval), "%c,", (((int *) var->value)[element]) ? 't' : 'f');
-                                       else
-                                               ecpg_raise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
 
                                        strcpy(mallocedval + strlen(mallocedval) - 1, "}");
                                }