[Kexi] Kexi python Scripting

Sebastian Sauer mail at dipe.org
Sun Mar 9 05:32:12 CET 2008


On Sunday 09 March 2008, Sebastian Sauer wrote:
> Hi Rüdiger :)
>
> Rüdiger Härtel wrote:
> > Here is the kexi project.
> >
> > Am Freitag 07 März 2008 14:03:45 schrieben Sie:
> >> Rüdiger Härtel said the following, On 2008-03-07 13:52:
> >> > I want to write a script to query some data from my db.
> >> >
> >> > the following works:
> >> >
> >> > cursor = connection.executeQueryString("SELECT * from emp where
> >> > country = 'Germany'")
> >> > ...
> >> >
> >> > but this does not work
> >> >
> >> > country = self.countries.get()
> >> > sqlStmt = "SELECT * from emp where country = %s" % country
> >> > cursor = connection.executeQueryString(sqlStmt)
>
> probably the country variable does contain the wrong value. Following works
> fine with your testdb;
>
> import kexiapp
> keximainwindow = kexiapp.get("KexiAppMainWindow")
> connection = keximainwindow.getConnection()
> country="Germany"
> sqlStmt = 'SELECT * from tabelle1 WHERE country = \'%s\';' % country
> cursor = connection.executeQueryString(sqlStmt)
> if not cursor:
> 	raise "No cursor"
> while not cursor.eof():
> 	for i in range( cursor.fieldCount() ):
> 		print "%s %s" % (str(i), cursor.value(i))
> 	cursor.moveNext()

ah, problem found...

replace
country = self.countryList.get()
with
country = str(self.countryList.get())
to turn that explicit into a local aware string.



More information about the Kexi mailing list