Hello,

I'm implementing the odbc support on pspp. Since I've never made a new feature to pspp, I would like to know if my implementation is good. I'm sending what I've
changed on get-data.c.

My implementation already receives the options passed on syntax, opens the connection with odbc and deal with errors. Now I "only" need to get results of the sql query.

Regards,

michel
diff --git a/src/language/data-io/get-data.c b/src/language/data-io/get-data.c
index 32202ba..efe096b 100644
--- a/src/language/data-io/get-data.c
+++ b/src/language/data-io/get-data.c
@@ -20,6 +20,7 @@
 
 #include <data/gnumeric-reader.h>
 #include <data/psql-reader.h>
+#include <data/odbc-reader.h>
 
 #include <data/dictionary.h>
 #include <data/format.h>
@@ -43,6 +44,7 @@
 static int parse_get_gnm (struct lexer *lexer, struct dataset *);
 static int parse_get_txt (struct lexer *lexer, struct dataset *);
 static int parse_get_psql (struct lexer *lexer, struct dataset *);
+static int parse_get_odbc (struct lexer *lexer, struct dataset *);
 
 int
 cmd_get_data (struct lexer *lexer, struct dataset *ds)
@@ -60,12 +62,78 @@ cmd_get_data (struct lexer *lexer, struct dataset *ds)
     return parse_get_txt (lexer, ds);
   else if (lex_match_id (lexer, "PSQL"))
     return parse_get_psql (lexer, ds);
+  else if (lex_match_id (lexer, "ODBC"))
+    return parse_get_odbc (lexer, ds);
 
   msg (SE, _("Unsupported TYPE %s"), lex_tokid (lexer));
   return CMD_FAILURE;
 }
 
 static int
+parse_get_odbc (struct lexer *lexer, struct dataset *ds)
+{
+  struct odbc_read_info odbc;
+  odbc.allow_clear = false;
+  odbc.conninfo = NULL;
+  odbc.str_width = -1;
+  odbc.sql = NULL;
+
+  lex_force_match (lexer, '/');
+
+  if (!lex_force_match_id (lexer, "CONNECT"))
+    goto error;
+
+  lex_force_match (lexer, '=');
+
+  if (!lex_force_string (lexer))
+    goto error;
+
+  odbc.conninfo = xstrdup (ds_cstr (lex_tokstr (lexer)));
+
+  lex_get (lexer);
+
+  while (lex_match (lexer, '/') )
+    {
+      if ( lex_match_id (lexer, "ASSUMEDSTRWIDTH"))
+	{
+	  lex_match (lexer, '=');
+	  odbc.str_width = lex_integer (lexer);
+	  lex_get (lexer);
+	}
+      else if ( lex_match_id (lexer, "UNENCRYPTED"))
+	{
+	  odbc.allow_clear = true;
+	}
+      else if (lex_match_id (lexer, "SQL"))
+	{
+	  lex_match (lexer, '=');
+	  if ( ! lex_force_string (lexer) )
+	    goto error;
+
+          odbc.sql = xstrdup (ds_cstr (lex_tokstr (lexer)));
+	  lex_get (lexer);
+	}
+     }
+
+  {
+    struct dictionary *dict = NULL;
+    struct casereader *reader = odbc_open_reader (&odbc, &dict);
+
+    if ( reader )
+      proc_set_active_file (ds, reader, dict);
+  }
+
+  return CMD_SUCCESS;
+
+ error:
+
+  ds_destroy (&odbc.sql);
+  free (odbc.conninfo);
+
+  return CMD_FAILURE;
+}
+
+static int
 parse_get_psql (struct lexer *lexer, struct dataset *ds)
 {
   struct psql_read_info psql;
_______________________________________________
pspp-dev mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/pspp-dev

Reply via email to