[svn] r7616: nemerle/trunk/macros/Data.n

nazgul svnadmin at nemerle.org
Mon Apr 23 22:33:18 CEST 2007


Log:
Check if null is allowed for given column in data-base. Patch by apanteleev

Author: nazgul
Date: Mon Apr 23 22:33:16 2007
New Revision: 7616

Modified:
   nemerle/trunk/macros/Data.n

Modified: nemerle/trunk/macros/Data.n
==============================================================================
--- nemerle/trunk/macros/Data.n	(original)
+++ nemerle/trunk/macros/Data.n	Mon Apr 23 22:33:16 2007
@@ -41,7 +41,7 @@
                        Nemerle.MacroTargets.Assembly)]
   macro ConfigureConnection (connClass : string, con_str : string, name : string = "")
   {
-    def mng = Nemerle.Macros.ImplicitCTX().Manager;
+    def mng = Nemerle.Macros.Manager ();
     if (Helper.connections.Contains (name))
       Message.FatalError ("Connection with name `" + name + "' is already defined")
     else {
@@ -193,7 +193,8 @@
       foreach (myRow :> DataRow in table.Rows){
         def col_type = myRow["DataType"].ToString ();
         def col_name = myRow["ColumnName"].ToString ();
-        def fetchexpr = Helper.GenerateFetchExpr (Nemerle.Macros.ImplicitCTX ().Manager, col_type, col_num);
+        def allow_null = myRow["AllowDBNull"] :> bool;
+        def fetchexpr = Helper.GenerateFetchExpr (Nemerle.Macros.Manager (), col_type, col_num, allow_null);
           
         // create runtime variables definition according to extracted types
         bodyseq = <[ def $(col_name : usesite) = $fetchexpr ]> :: bodyseq;
@@ -375,7 +376,7 @@
       (fquery.ToString (), tpars, pars_init)
     }
   
-    public GenerateFetchExpr (mng : ManagerClass, typeName : string, colIdx : int) : Parsetree.PExpr {
+    public GenerateFetchExpr (mng : ManagerClass, typeName : string, colIdx : int, allow_null: bool) : Parsetree.PExpr {
       def type_suff = 
         if (typeName.StartsWith ("System."))
           typeName.Substring (7)
@@ -385,13 +386,18 @@
         match (mng.NameTree.LookupExactType (typeName)) {
           | Some (t) => 
             def rawTy = <[ $(Util.ExprOfQid (typeName)) ]>;
-            if (t.GetMemType ().CanBeNull) rawTy
+            if (!allow_null || t.GetMemType ().CanBeNull) rawTy
             else <[ $rawTy ? ]>
           | None => Message.FatalError ("DB provider returned unknown type name: " + typeName);
         }
       
+      def real_fetch = <[ reader.$("Get" + type_suff : usesite) ($(colIdx : int)) : $retTy ]>;
+      
+      if(allow_null)
       <[ if (reader.IsDBNull ($(colIdx : int))) null : $retTy
-         else reader.$("Get" + type_suff : usesite) ($(colIdx : int)) : $retTy ]>
+           else $real_fetch ]>
+      else
+        real_fetch
     }
   }
 }



More information about the svn mailing list