From: Jos v.d.V. <jo...@us...> - 2007-05-16 20:34:28
|
Update of /cvsroot/win32forth/win32forth-stc/demos/ADO In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv9460 Added Files: ADOreadme.txt EX_Connstr.f EX_Create.f EX_Dump.f EX_Ins.f EX_InsSQL.f test.mdb Log Message: Jos: Tom Dixon's ADO-demo's --- NEW FILE: EX_Create.f --- \ Example of Creating Database Tables \ Tom Dixon needs ADO needs EX_Connstr.f \ load in the connection string \ declare the objects that we are going to work with ADOConnection conn ADOCursor cursor start: conn \ start the connection connstr count setconnstring: conn \ set the connection string adModeReadWrite setmode: conn \ set the mode to read and write connect: conn \ connect to the database start: cursor \ start the cursor conn SetConnection: cursor \ tell cursor to use the 'conn' connection object adLockOptimistic SetLockType: cursor \ Lock on updates create qstr 256 allot \ Create a generic Globals Table s" CREATE TABLE globals ( " qstr place s" global_name varchar(64) not null, " qstr +place s" global_char varchar(255) null, " qstr +place s" global_text text null, " qstr +place s" global_datetime datetime null, " qstr +place s" global_integer int null, " qstr +place s" global_float float null) " qstr +place qstr count execute: cursor close: cursor close: conn --- NEW FILE: ADOreadme.txt --- These files are examples on how to use the ADO classes. In order to run them, you must setup a database and make sure that the connection string in EX_Connstr.F points to it. An access database is the easiest to make. All the examples use EX_Connstr.f to connect. EX_Create.f - creates a table in the database EX_InsSQL.F - inserts records into the table (through SQL) EX_Ins.F - inserts records programmatically EX_Dump.F - dumps a column of the table If you run the examples in the order listed, there should be no errors. Drop the table from the database to run them again. --- NEW FILE: EX_Connstr.f --- \ Database Connection Example \ Tom Dixon \ ADO connects to a database through the connection string. \ This connection string can take several different formats. \ For our example, we will only use Access needs ADO defined connstr nip 0= [if] create connstr 256 allot [then] s" DRIVER={Microsoft Access Driver (*.mdb)};" connstr place \ this may need to be changed to where ever the test database is. s" DBQ=C:\win32forth-stc\demos\ADO\test.mdb" connstr +place \ For a large list of other connection string options, as well as examples \ of other databases, look at \ http://www.carlprothman.net/Default.aspx?tabid=81 --- NEW FILE: test.mdb --- (This appears to be a binary file; contents omitted.) --- NEW FILE: EX_Ins.f --- \ Example of inserting data programmatically \ Tom Dixon \ This example shows how to insert data programmatically. needs ADO needs EX_Connstr.f \ load in the connection string \ declare the objects that we are going to work with ADOConnection conn ADOCursor cursor start: conn \ start the connection connstr count setconnstring: conn \ set the connection string adModeReadWrite setmode: conn \ set the mode to read and write connect: conn \ connect to the database start: cursor \ start the cursor conn SetConnection: cursor \ tell cursor to use the 'conn' connection object adLockOptimistic SetLockType: cursor \ Lock on updates \ retrieve the table s" SELECT * FROM globals" execute: cursor \ add a float global addrow: cursor \ add a row to the end s" PI" 0 setstr: cursor 3.14159265358979e0 5 setfloat: cursor update: cursor \ add an integer global addrow: cursor s" Major Version" 0 setstr: cursor 3 4 setint: cursor update: cursor \ add a date global addrow: cursor s" Testdate" 0 setstr: cursor time&date 3 setdatetime: cursor update: cursor \ add a varchar addrow: cursor s" Owner" 0 setstr: cursor s" Billy Bones" 2 setstr: cursor update: cursor \ clean up close: cursor close: conn --- NEW FILE: EX_Dump.f --- \ Example of Selecting and displaying Data \ Tom Dixon \ This example shows how to access data from a cursor needs ADO needs EX_Connstr.f \ load in the connection string \ declare the objects that we are going to work with ADOConnection conn ADOCursor cursor start: conn \ start the connection connstr count setconnstring: conn \ set the connection string connect: conn \ connect to the database start: cursor \ start the cursor conn SetConnection: cursor \ tell cursor to use the 'conn' connection object \ retrieve the table s" SELECT * FROM globals" execute: cursor : testdump ( -- ) cr movefirst: cursor 0 fieldname: cursor dup >r type cr r> 0 ?do [char] - emit loop cr begin 0 getstr: cursor type cr movenext: cursor eof: cursor until ; testdump \ clean up close: cursor close: conn --- NEW FILE: EX_InsSQL.f --- \ Example of inserting data into a database VIA SQL \ Tom Dixon \ This example shows how to execut SQL queries to insert \ data into a table needs ADO needs EX_Connstr.f \ load in the connection string \ declare the objects that we are going to work with ADOConnection conn ADOCursor cursor start: conn \ start the connection connstr count setconnstring: conn \ set the connection string adModeReadWrite setmode: conn \ set the mode to read and write connect: conn \ connect to the database start: cursor \ start the cursor conn SetConnection: cursor \ tell cursor to use the 'conn' connection object adLockOptimistic SetLockType: cursor \ Lock on updates create qstr 256 allot s" INSERT INTO globals (global_name, global_text, global_integer, global_datetime)" qstr place s" VALUES('StartDate','The Date the database was started',1,now())" qstr +place qstr count execute: cursor close: cursor close: conn |