Changeset: 6eaf46a85e68 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/6eaf46a85e68
Modified Files:
        clients/odbc/driver/ODBCAttrs.c
        clients/odbc/driver/ODBCAttrs.h
        clients/odbc/driver/SQLBrowseConnect.c
Branch: odbc-tls
Log Message:

Split attr_setting suggest_values into separate option strings

So drvcfg.c can display them in a combobox


diffs (87 lines):

diff --git a/clients/odbc/driver/ODBCAttrs.c b/clients/odbc/driver/ODBCAttrs.c
--- a/clients/odbc/driver/ODBCAttrs.c
+++ b/clients/odbc/driver/ODBCAttrs.c
@@ -17,22 +17,30 @@
 #include <odbcinst.h>
 #endif
 
+static const char *suggest_on_off[] = {
+       "On",
+       "Off",
+       NULL,
+};
 
-#define SUGGEST_BOOLEAN "{True,False}"
+static const char *suggest_monetdb[] = {
+       "monetdb",
+       NULL,
+};
 
 const struct attr_setting attr_settings[] = {
-       { "UID", "User", MP_USER },
-       { "PWD", "Password", MP_PASSWORD },
+       { "UID", "User", MP_USER, .is_enum = false, .values = suggest_monetdb },
+       { "PWD", "Password", MP_PASSWORD, .is_enum = false, .values = 
suggest_monetdb },
        { "DATABASE", "Database", MP_DATABASE },
        { "PORT", "Port", MP_PORT },
-       { "HOST", "Server", MP_HOST },
+       { "HOST", "Server", MP_HOST, },
        { "SOCK", "Unix Socket", MP_SOCK },
-       { "TLS", "Encrypt", MP_TLS, .suggest_values = SUGGEST_BOOLEAN },
+       { "TLS", "Encrypt", MP_TLS, .is_enum = true, .values = suggest_on_off },
        { "CERT", "Server Certificate", MP_CERT },
        { "CERTHASH", "Server Certificate Hash", MP_CERTHASH },
        { "CLIENTKEY", "Client Key", MP_CLIENTKEY },
        { "CLIENTCERT", "Client Certificate", MP_CLIENTCERT },
-       { "AUTOCOMMIT", "Autocommit", MP_AUTOCOMMIT, .suggest_values = 
SUGGEST_BOOLEAN },
+       { "AUTOCOMMIT", "Autocommit", MP_AUTOCOMMIT, .is_enum = true, .values = 
suggest_on_off },
        { "SCHEMA", "Schema", MP_SCHEMA },
        { "TIMEZONE", "Time Zone", MP_TIMEZONE },
        { "REPLYSIZE", "Reply Size", MP_REPLYSIZE },
diff --git a/clients/odbc/driver/ODBCAttrs.h b/clients/odbc/driver/ODBCAttrs.h
--- a/clients/odbc/driver/ODBCAttrs.h
+++ b/clients/odbc/driver/ODBCAttrs.h
@@ -21,11 +21,11 @@
 #include "msettings.h"
 
 struct attr_setting {
-       const char *name;                // canonical attribute name
-       const char *alt_name;            // user-facing attribute name
-       mparm parm;
-       // optional
-       const char *suggest_values;      // SQLBrowseConnect suggestion, or 
NULL for "?"
+       const char *name;          // canonical attribute name
+       const char *alt_name;      // user-facing attribute name
+       mparm parm;                // the corresponding msetting parameter
+       bool is_enum;              // fixed set of values
+       const char **values;       // NULL or NULL-terminated array of options
 };
 
 // defined in SQLConnect.c, also used in SQLBrowseConnect.c
diff --git a/clients/odbc/driver/SQLBrowseConnect.c 
b/clients/odbc/driver/SQLBrowseConnect.c
--- a/clients/odbc/driver/SQLBrowseConnect.c
+++ b/clients/odbc/driver/SQLBrowseConnect.c
@@ -53,11 +53,18 @@ suggest_settings(ODBCDbc *dbc, char **bu
                mparm parm = entry->parm;
                if (dbc->setting_touched[(int)parm] == touched_as) {
                        const char *sep = *pos > 0 ? ";" : "";
-                       const char *values = entry->suggest_values ? 
entry->suggest_values : "?";
-                       reallocprintf(
-                               buf, pos, cap,
-                               "%s%s%s:%s=%s",
-                               sep, prefix, entry->name, entry->alt_name, 
values);
+                       reallocprintf(buf, pos, cap, "%s%s%s:%s=?", sep, 
prefix, entry->name, entry->alt_name);
+                       if (entry->is_enum) {
+                               assert(entry->values != NULL);
+                               *pos -= 1;  // eat the '?'
+                               sep = "{";
+                               for (const char **p = entry->values; *p; p++) {
+                                       const char *item = *p;
+                                       reallocprintf(buf, pos, cap, "%s%s", 
sep, item);
+                                       sep = ",";
+                               }
+                               reallocprintf(buf, pos, cap, "}");
+                       }
                }
        }
 }
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to