Re: [gnome-db] CSV example



Hi Denis,

This is a snippet of my Vala code to import a CSV file. I hope this
helps you.

	public Gda.DataModel? load_csv_file(string? table_name){
		try{
		    	var options = new Gda.Set.from_spec_string("<data-set-spec>
		    				<parameters>
							<parameter id=\"SEPARATOR\" name=\"SEPARATOR\" gdatype=
\"gchararray\">
		    						<gda_value>"+ props.csv_separator +"</gda_value>
		    					</parameter>
							<parameter id=\"ESCAPE_CHAR\" name=\"ESCAPE_CHAR\" gdatype=
\"gchararray\">
		    						<gda_value>"+ props.csv_escape_char +"</gda_value>
		    					</parameter>
		    					<parameter id=\"TITLE_AS_FIRST_LINE\" name=
\"TITLE_AS_FIRST_LINE\" gdatype=\"gboolean\">
		    						<gda_value>"+ props.csv_has_header.to_string()
+"</gda_value>
		    					</parameter>
		    				 </parameters>
		    				 </data-set-spec>");
		    	var dmi = Gda.DataModelImport.new_file(props.csv_file_name, true,
options);
		    	return dmi;
		}catch(GLib.Error err){
			ErrorMessage(err.message);
		}

		return null;
	}




On Fri, 2011-12-30 at 14:40 +0200, Denis Kuzmenok wrote:
> Or any example with DataModelImport in Vala.
> I try doing
> var  dm  =  new  Gda.DataModel  (DataModelImport.from_file("test.csv",
> false));
> 
> but get "for enough arguments".. Can someone help with how to read CSV
> and get it's contents?
> 
> PS: Vala 0.14.1, libgda 5.0.2
> 
> 
> > Hi, guys.
> 
> > Can you point me to CSV parsing example?
> > Thanks, in advance.
> 
> > _______________________________________________
> > gnome-db-list mailing list
> > gnome-db-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gnome-db-list
> 
> 
> 
> _______________________________________________
> gnome-db-list mailing list
> gnome-db-list gnome org
> http://mail.gnome.org/mailman/listinfo/gnome-db-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]