[svn] r6766: nemerle/trunk/macros: dataNpgsql.n dataSqlClient.n

nazgul svnadmin at nemerle.org
Wed Oct 18 18:33:50 CEST 2006


Log:
Make sqlclient and npgsql macros more common

Author: nazgul
Date: Wed Oct 18 18:33:42 2006
New Revision: 6766

Modified:
   nemerle/trunk/macros/dataNpgsql.n
   nemerle/trunk/macros/dataSqlClient.n

Modified: nemerle/trunk/macros/dataNpgsql.n
==============================================================================
--- nemerle/trunk/macros/dataNpgsql.n	(original)
+++ nemerle/trunk/macros/dataNpgsql.n	Wed Oct 18 18:33:42 2006
@@ -226,8 +226,7 @@
 
     /// final code for entire sql loop
     <[
-      using (querycmd = NpgsqlCommand ($(query : string), $conn)) 
-      {
+      using (querycmd = NpgsqlCommand ($(query : string), $conn)) {
         { .. $pars_init };
         def reader = querycmd.ExecuteReader ();
         while (reader.Read ()) { ..$bodyseq };

Modified: nemerle/trunk/macros/dataSqlClient.n
==============================================================================
--- nemerle/trunk/macros/dataSqlClient.n	(original)
+++ nemerle/trunk/macros/dataSqlClient.n	Wed Oct 18 18:33:42 2006
@@ -76,7 +76,6 @@
         mycmd.Parameters.Add (name, dbtype).Value = dbvalue;
       });
       // try to execute query chcecking its syntax and typecorrectness
-
       _ = mycmd.ExecuteNonQuery ()
     }
     catch {
@@ -89,11 +88,11 @@
     };
     
     <[
-      def querycmd = SqlCommand ($(query : string), $conn);
+      using (querycmd = SqlCommand ($(query : string), $conn))
+      {
       { .. $pars_init };
-      def result = querycmd.ExecuteNonQuery ();
-      querycmd.Dispose ();
-      result
+        querycmd.ExecuteNonQuery ();
+      }
     ]>
   }
 
@@ -102,11 +101,11 @@
     def (query, tpars, pars_init) =
       Tools.ExtractParameters (Nemerle.Macros.ImplicitCTX (), query, '@');
 
-    mutable col_type = null;
-
     // create compile-time query to check syntax and types in query
     def mytran = get_connection (con_name).BeginTransaction ();          
     def mycmd = SqlCommand (query, get_connection (con_name), mytran);
+
+    mutable col_type = null;
     try {
       tpars.Iter (fun (name, tvar : Typedtree.TExpr) {
         def (dbtype, dbvalue) = type_representant (tvar.ty.Fix ());
@@ -133,11 +132,11 @@
       
     /// final code for entire sql loop
     <[
-      def querycmd = SqlCommand ($(query : string), $conn);
+      using (querycmd = SqlCommand ($(query : string), $conn))
+      {
       { .. $pars_init };
-      def result = (querycmd.ExecuteScalar () :> $col_type);
-      querycmd.Dispose ();
-      result
+        (querycmd.ExecuteScalar () :> $col_type);
+      }
     ]>
   }
 
@@ -168,11 +167,11 @@
 
     /// final code for entire sql loop
     <[
-      def querycmd = SqlCommand ($(query : string), $conn);
+      using (querycmd = SqlCommand ($(query : string), $conn)) 
+      {
       { .. $pars_init };
-      def result = querycmd.ExecuteReader ();
-      querycmd.Dispose ();
-      result
+        querycmd.ExecuteReader ();
+      }
     ]>
   }
   
@@ -201,10 +200,14 @@
       foreach(myRow :> DataRow in table.Rows){
         def col_type = myRow["DataType"].ToString ();
         def col_name = myRow["ColumnName"].ToString ();
+        def type_suff = 
+          if (col_type.StartsWith ("System."))
+            col_type.Substring (7)
+          else col_type;
 
         // create runtime variables definition according to extracted types
         bodyseq = <[ def $(col_name : usesite) =
-                        reader.$("Get" + col_type : usesite) ($(col_num : int)) ]>
+                        reader.$("Get" + type_suff : usesite) ($(col_num : int)) ]>
                     :: bodyseq;
         ++col_num;
       };
@@ -222,19 +225,17 @@
 
     /// final code for entire sql loop
     <[
-      def querycmd = SqlCommand ($(query : string), $conn);
+      using (querycmd = SqlCommand ($(query : string), $conn)) {
       { .. $pars_init };
       def reader = querycmd.ExecuteReader ();
       while (reader.Read ()) { ..$bodyseq };
       reader.Close ();
-      querycmd.Dispose ();
+      }
     ]>
   }
 
   module Helper {
-    internal connections : Hashtable [string, SqlConnection];
-
-    public this () { connections = Hashtable () }
+    internal connections : Hashtable [string, SqlConnection] = Hashtable ();
 
     internal get_connection (name : string) : SqlConnection
     {



More information about the svn mailing list