Re: [gnome-db] import from csv

Andrea Zagli <[email protected]>
Newsgroups gmane.comp.gnome.db
Message-ID <[email protected]>
Il giorno gio 28 ott 2010 08:50:35 CEST, Andrea Zagli ha scritto:
> Il giorno gio 28 ott 2010 08:26:09 CEST, Andrea Zagli ha scritto:
>>> [...]
>
> i just tried the sample in git repository (attached) and i got the   
> same results
>
> can be windows the problem? or the libgda version that i use? on the  
>  weekend i'll try both

yes the problem is only under windows

patch attached

_______________________________________________
gnome-db-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gnome-db-list
patch.patch (text/x-c, 3 KB)
diff --git a/libgda/gda-data-model-import.c b/libgda/gda-data-model-import.c
index fdd6f42..0c70db0 100644
--- a/libgda/gda-data-model-import.c
+++ b/libgda/gda-data-model-import.c
@@ -546,7 +546,7 @@ gda_data_model_import_set_property (GObject *object,
 
 			/* file opening */
 			model->priv->src.mapped.fd = open (model->priv->src.mapped.filename, O_RDONLY); /* Flawfinder: ignore */
-			if (model->priv->src.mapped.fd < 0) {
+			if (model->priv->src.mapped.fd <= 0) {
 				/* error */
 				add_error (model, strerror(errno));
 				return;
@@ -572,18 +572,60 @@ gda_data_model_import_set_property (GObject *object,
 					return;
 				}
 #else
-				HANDLE view = CreateFileMapping((HANDLE)model->priv->src.mapped.fd, 
+				HANDLE hFile = CreateFile (model->priv->src.mapped.filename,
+				                           GENERIC_READ,
+										   FILE_SHARE_READ,
+										   NULL,
+										   OPEN_EXISTING,
+										   FILE_ATTRIBUTE_NORMAL,
+										   NULL);
+				if (!hFile)
+					{
+						LPVOID lpMsgBuf;
+						DWORD dw = GetLastError();
+						FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
+									   FORMAT_MESSAGE_FROM_SYSTEM |
+									   FORMAT_MESSAGE_IGNORE_INSERTS,
+									   NULL,
+									   dw,
+									   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+									   (LPTSTR) &lpMsgBuf,
+									   0, NULL);
+						add_error (model, (gchar *)lpMsgBuf);
+						return;
+					}
+				HANDLE view = CreateFileMapping(hFile, 
 								NULL, PAGE_READONLY|SEC_COMMIT, 0,0 , NULL);
 				if (!view) {
 					/* error */
-					add_error (model, sys_errlist [errno]);
+					LPVOID lpMsgBuf;
+					DWORD dw = GetLastError();
+					FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
+					               FORMAT_MESSAGE_FROM_SYSTEM |
+								   FORMAT_MESSAGE_IGNORE_INSERTS,
+								   NULL,
+								   dw,
+								   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+								   (LPTSTR) &lpMsgBuf,
+								   0, NULL);
+					add_error (model, (gchar *)lpMsgBuf);
 					return;
 				}
 				model->priv->src.mapped.start = MapViewOfFile(view, FILE_MAP_READ, 0, 0, 
 									      model->priv->src.mapped.length);
 				if (!model->priv->src.mapped.start) {
 					/* error */
-					add_error (model, sys_errlist [errno]);
+					LPVOID lpMsgBuf;
+					DWORD dw = GetLastError();
+					FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
+					               FORMAT_MESSAGE_FROM_SYSTEM |
+								   FORMAT_MESSAGE_IGNORE_INSERTS,
+								   NULL,
+								   dw,
+								   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+								   (LPTSTR) &lpMsgBuf,
+								   0, NULL);
+					add_error (model, (gchar *)lpMsgBuf);
 					return;
 				}
 #endif
@@ -633,8 +675,8 @@ gda_data_model_import_set_property (GObject *object,
 
 	/* here we now have a valid data to analyze, try to determine the real kind of data 
 	 * (CVS text of XML) */
-	if (model->priv->format != FORMAT_XML_NODE) {
-		g_assert (model->priv->data_start);
+	if (model->priv->format != FORMAT_XML_NODE
+	    && model->priv->data_start) {
 		if (!strncmp (model->priv->data_start, "<?xml", 5)) 
 			model->priv->format = FORMAT_XML_DATA;
 		else
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.