Hi,

Thanks again for your time and, again, I have only just had time to look 
at this. I am using mysql.

I have had a look at the code you posted, tried loads of variants, but 
am still getting the same syntax error. What I am trying to do, just to 
try and get some sort of handle on the basic syntax of all this, is a 
very simple bit of code.

I have a table called People. The table has three columns: ID (the 
unique ID - auto incremented), Name and Number. Name is text, Number is 
integer.

I have made a form with two lineeditfields, one for Name and one for 
Number, and a combo box for choosing the ID.

All I want to do, just to get me started and get a basic understanding 
of how this code is put together is this:

Press a button on the form and write the values that are in the 
lineeditfields into the appropriate columns on the table.

I've called the lineeditfields on the form NameInputField and 
TelephoneInputField.

I've tried doing this for On Click:

filtervalue=hk.thisform.get_pyvisible(NameInputField).value()
sqlstring = "INSERT INTO" + str(People) + ("Name") VALUES + (" + 
filtervalue")
query.set_sql(sqlstr)
status=query.execute()

And, indeed, a million variations on line two, but I just keep getting 
the same syntax error. I feel that if I can just suss this one basic 
thing out, a lot of this will fall into place.

I think I'm repeating myself actually, so very sorry if I've completely 
misunderstood something basic here you were trying to tell me, I really 
need to take small steps to try and get used to this. I am a C (not C++) 
programmer, so coding isn't an issue, it's just a case of me learning a 
new system (I hope!)

Many thanks again.

Rob


Jesus Arocho wrote:
> 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
> 
> 

-------------------------------------------------------------------------
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