I do not know what database you are using.  the code sections below are from 
forms I created for a database created in postgresql.  The correct use of 
quotes is database engine dependent.  If I recall correctly, the code section 
you gave had the name of the widget inserted directly into the sql statement.  
So my first code example was to point that out.

So, let's see.  Let us say you want to collect some information in a form and 
use that information to send a SQL command to the database engine.   The code 
section below does exactly that.  First, I assign the values of interest into 
variables, d0 thru d...  Then, I construct the SQL statement sqlstr.  Note 
the statement has \"" inserted before the table names and the column names.  
This is so because postgresql expects the object designators as strings and 
so must have " before and after; but, if I just simply create it 
as "objectname" python will understand the string to end at the second " and 
then return an error.  The single quotes for the d... sequence serves a 
similar purpose.

else:
                
d7=gridact.datasource().column_by_name("actresource").curval_asstring()
                
d2=gridact.datasource().column_by_name("acttype").curval_asstring()
                
d3=gridact.datasource().column_by_name("actsubjectid").curval_asstring()
                
d4=gridact.datasource().column_by_name("actcourseid").curval_asstring()
                
d5=gridact.datasource().column_by_name("acttopic").curval_asstring()
                d5=d5.replace("'","\\'")
                
d6=gridact.datasource().column_by_name("actinstructions").curval_asstring()
                d6=d6.replace("'","\\'")
                
#d7=gridact.datasource().column_by_name("actresource").curval_asstring()
                
d8=gridact.datasource().column_by_name("actref").curval_asstring()
                
#d9=gridact.datasource().column_by_name("actpoints").curval_asstring()
                
d10=gridact.datasource().column_by_name("actnotes").curval_asstring()
                
#d11=gridact.datasource().column_by_name("acttime").curval_asstring()
                
d12=gridact.datasource().column_by_name("grade").curval_asstring()
                
d13=gridact.datasource().column_by_name("actid").curval_asstring()
                #build sql string

                sqlstr="INSERT INTO \"" + str(studenttbl) + "\" 
(\"studactsequence\", 
\"studactorder\", \"studacttype\", \"studactsubjectid\", \"studactcourseid\", 
\"studacttopic\", \"studactinstructions\", \"studactres\", \"studactref\", 
\"studactmaxpoints\", \"studactnotes\", \"studacttime\", \"studactlevel\", 
\"studactactid\", \"studactstart\") VALUES (" + d0 + ", " + d1 + ", '" + d2 
+ "', " + d3 + ", " + d4 + ", '" + d5 + "', '" + d6 + "', " + d7 + ", '" + d8 
+ "', " + d9 + ", '" + d10 + "', " + d11 + ", " + d12  + ", " + d13 + ", '" + 
datestr + "');"
                
                #sqlstr="INSERT INTO TABLE \"" + str(studenttbl) + "\" 
(\"studactstudid\") 
VALUES (" + colstudent  + ");"

                #hk_this.show_warningmessage(sqlstr)
                db=hk_thisform.database()
                query=db.new_actionquery()
                
                query.set_sql(sqlstr)
                status=query.execute()

************************************************************************

#get current value of combobox: function returns viewcolumn
filtervalue=hk_thisform.get_pyvisible("cbosubject").value()

#so we must find the associated listcolumn value by finding the corresponding 
value in the same row
rownum=hk_thisform.get_pyvisible("cbosubject").viewcolumn().find(0,1000,filtervalue)
hk_thisform.get_pyvisible("cbosubject").listdatasource().goto_row(rownum)
filtervalue=hk_thisform.get_pyvisible("cbosubject").listcolumn().asstring()

filterstring="subjectid = " + filtervalue

datatbl=hk_thisform.get_datasource(8)
datatbl.disable()
datatbl.set_temporaryfilter(filterstring)
datatbl.set_use_temporaryfilter(True)
datatbl.enable()

#this is the dummy table used to in the cboCourse object datasource to allow 
it to refresh
datatbltmp=hk_thisform.get_datasource(7)
datatbltmp.disable()
datatbltmp.enable()

************************************************

#get current value of combobox: function returns viewcolumn
filtervalue=hk_thisform.get_pyvisible("cbolevel").value()

#so we must find the associated listcolumn value by finding the corresponding 
value in the same row
rownum=hk_thisform.get_pyvisible("cbolevel").viewcolumn().find(0,1000,filtervalue)
hk_thisform.get_pyvisible("cbolevel").listdatasource().goto_row(rownum)
filtervalue=hk_thisform.get_pyvisible("cbolevel").listcolumn().asstring()

#get current value of combobox: function returns viewcolumn
filtervalue2=hk_thisform.get_pyvisible("cbosubject").value()

#so we must find the associated listcolumn value by finding the corresponding 
value in the same row
rownum=hk_thisform.get_pyvisible("cbosubject").viewcolumn().find(0,1000,filtervalue2)
hk_thisform.get_pyvisible("cbosubject").listdatasource().goto_row(rownum)
filtervalue2=hk_thisform.get_pyvisible("cbosubject").listcolumn().asstring()

#now we can reset the grid filter
gridact=hk_thisform.get_pyvisible("gridtblact")
filterstring ="actsubjectid = " + filtervalue2
#hk_this.show_warningmessage(filterstring)
gridact.datasource().disable()
gridact.datasource().set_temporaryfilter(filterstring)
gridact.datasource().set_use_temporaryfilter(True)
gridact.datasource().set_temporarysorting("actcourseid, actsequence")
gridact.datasource().set_use_temporarysorting(True)
gridact.datasource().enable()

#now we can reset the grid filter
gridstudact=hk_thisform.get_pyvisible("gridtblstudact")
filterstring="studactlevel = " + filtervalue + " AND studactsubjectid = " + 
filtervalue2
#hk_this.show_warningmessage(filterstring)
gridstudact.datasource().disable()
gridstudact.datasource().set_temporaryfilter(filterstring)
gridstudact.datasource().set_use_temporaryfilter(True)
gridstudact.datasource().set_temporarysorting("studactcourseid, 
studactsequence")
gridstudact.datasource().set_use_temporarysorting(True)
gridstudact.datasource().enable()

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Hk-classes-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hk-classes-discuss

Reply via email to