Largest Provider of Commercial Smalltalk
Cincom is one of the largest commercial providers of Smalltalk, with twice as many customers and partners as other commercial providers.

Tom Nies

Get Started

ODBC 3.0 Support in Cincom® VisualWorks®

Posted on in Categories VisualWorks

In VisualWorks 8.1.1, we’ve included a new package called ODBC3EXDI under preview, which uses ODBCEXDI as a prerequisite and makes use of ODBC 3.0 APIs. You can find the package in folder ……VisualWorksRoot\preview\database.

In ODBC3EXDI, there are new classes that use ODBC 3.0 APIs.  If your application uses ODBCConnection, it will continue to work exactly the same as before. However, if you want to take advantage of the ODBC 3.0 support, you can use ODBC3Connection.  This means that in VisualWorks 8.1.1, ODBC 2.0 is the default behavior while ODBC 3.0 is selectable.

We are planning to merge this ODBC 3.0 driver into the existing ODBCEXDI package and release it in VisualWorks 8.2.  At that time, the standalone preview package will be dropped, and we will extend the support to threaded ODBC connect and ObjectStudio’s ODBC wrapper.  We may keep one of the two drivers as default and the other as selectable.

The following is an example of using ODBC3Connection in VisualWorks:

"Use ODBC3Connection to connect to an SQL Server database."
conn := ODBC3Connection new.
conn username: 'username';
password: 'password';
environment: 'DSNToSQLServer'.
conn connect.
"Check the version of ODBC."
conn odbcVersion.
"Get an ODBC3Session."
sess := conn getSession.
"Re-use the session to create a test table."
sess prepare:  'CREATE TABLE TESTTABLE(
                cid int ,
                cname varchar (100)
)';
                execute;
                answer;
                answer.
"The SQL used to do insert."
sql := 'INSERT INTO TESTTABLE VALUES (1, ''test1'')'.
"Re-use the session to do a direct execution."
sess executeDirect: sql;
                answer;
                answer.
"Re-use the session to go through a prepare process."
sess prepare: sql.
sess       execute;
                                answer;
                                answer.
"The SQL used to do insert using binding."
sql := 'INSERT INTO TESTTABLE VALUES (?, ?)'.
sess prepare: sql.
sess bindInput: (Array with: 2 with: 'test2');
                                execute;
                                answer;
                                answer.
"Set the number of records being inserted."
loopCount := 10.
"Test preparing once, and binding and executing multiple times."
sess prepare: sql.
1 to: loopCount do: [ :i|
                sess bindInput: (Array with: i with: ('test', i printString));
                                execute;
                                answer;
                                answer.
].
"Test array-binding."
 numArray := Array new: loopCount.
 stringArray := Array new: loopCount.
1 to: loopCount do: [ :i|
                                numArray at: i put: i.
                                stringArray at: i put: ('test', i printString).
].
bindArray := Array with: numArray with: stringArray.
sess bindInput: bindArray;
                                execute;
                                answer;
                                answer.
"Verify the data."
sess := conn getSession.
sql := 'SELECT * from TESTTABLE'.
sess prepare: sql;
execute.
ans := sess answer.
res := ans upToEnd inspect.
sess answer.
"Test array-fetching."
sess := conn getSession.
sess blockFactor: 10.
sql := 'SELECT * from TESTTABLE'.
sess prepare: sql;
                execute.
ans := sess answer.
res := ans upToEnd inspect.
sess answer.