[m-dev.] diff: clean up odbc interface.

Tyson Dowd trd at cs.mu.OZ.AU
Mon Nov 1 14:36:25 AEDT 1999


Estimated hours taken: 4

Update odbc library.  

This code now works with iODBC 2.50 (which is nice because it will
ship with Debian 2.2).  I have tested it and managed to retrieve all
of a reasonably large database from MySQL without problems.

Some errors introduced by fjh in his memory allocation cleanup have been
fixed too.

extras/odbc/odbc.m:
	Remove some of the work arounds for bugs in iOBDC 2.12 since
	they have been fixed in iODBC 2.50.

	Include std_util in the interface (since we use pair).	

	Use MR_GC_NEW and MR_GC_NEW_ARRAY to allocate statements
	and rows.   These allocations have to match the deallocations
	later that are done with MR_GC_free.  It might be better to
	allocate statements and rows using normal malloc, but this
	approach is conservative and works fine.  It may need to be
	revisited if this module is made to work with accurate GC.



cvs server: Diffing .
Index: odbc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/odbc/odbc.m,v
retrieving revision 1.8
diff -u -r1.8 odbc.m
--- odbc.m	1999/10/18 15:47:39	1.8
+++ odbc.m	1999/11/01 03:11:53
@@ -60,7 +60,7 @@
 
 :- interface.
 
-:- import_module io, list.
+:- import_module io, list, std_util.
 
 %-----------------------------------------------------------------------------%
 
@@ -305,17 +305,9 @@
 
 #include ""isql.h""
 #include ""isqlext.h""
-#include ""odbc_funcs.h""
-#include ""odbc_types.h""
+/* #include ""odbc_funcs.h"" */
+#include ""sqltypes.h""
 
-	/* 
-	** iODBC 2.12 doesn't define SQL_NO_TOTAL, so we define it to
-	** something random. It must be negative because a positive value 
-	** where SQL_NO_TOTAL is returned is the length of the data.
-	*/
-#ifndef SQL_NO_TOTAL
-#define SQL_NO_TOTAL (-1451)
-#endif
 	/*
 	** Again, iODBC 2.12 doesn't define this, so define it to something
 	** harmless.
@@ -987,7 +979,7 @@
 
 
 		/* Doing manual deallocation of the statement object. */
-	statement = MR_NEW(MODBC_Statement);
+	statement = MR_GC_NEW(MODBC_Statement);
 		
 	statement->num_columns = 0;
 	statement->row = NULL;
@@ -1117,7 +1109,7 @@
 	** Allocate an array containing the info for each column.
 	** The extra column is because ODBC counts columns starting from 1.
 	*/
-	statement->row = MR_NEW_ARRAY(MODBC_Column, num_columns + 1);
+	statement->row = MR_GC_NEW_ARRAY(MODBC_Column, num_columns + 1);
 
 	/*
 	** Use SQLBindCol unless there are columns with no set maximum length.
@@ -1188,7 +1180,7 @@
 			** Do the buffer allocation once for columns which
 			** have a fixed maximum length. 
 			*/
-			column->data = newmem(column->size);
+			column->data = MR_GC_malloc(column->size);
 		}
 				
 	} /* for */
@@ -1912,20 +1904,8 @@
 			Status::out, Messages::out, IO0::di, IO::uo),
 		may_call_mercury,
 "{
-		/*
-		** Note that iODBC-2.12 doesn't implement 
-		** SQLDataSources, and always returns SQL_SUCCESS, 
-		** causing an infinite loop if we call the stub.
-		*/
-#ifdef MODBC_IODBC
-	Status = SQL_NO_DATA_FOUND;
-	SourceNames = MR_list_empty();
-	SourceDescs = MR_list_empty();
-	Messages = MR_list_empty();
-#else /* !MODBC_IODBC */
 	Status = odbc_do_get_data_sources(&SourceNames, 
 			&SourceDescs, &Messages);
-#endif /* !MODBC_IODBC */
 
 	IO = IO0;
 }").


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't eveyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list