home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxsqlmin.zip / tester.cmd < prev   
OS/2 REXX Batch file  |  1997-06-11  |  38KB  |  822 lines

  1. /*
  2.  * This program is the test suite for Rexx/SQL
  3.  *
  4.  * To use it you must do the following:
  5.  * 1.  set environment variables REXXSQL_USERNAME, REXXSQL_PASSWORD
  6.  *     and REXXSQL_SERVER to values of a valid username, password and
  7.  *     database server respectively.
  8.  *     Typical values for each tested database follows:
  9.  *
  10.  *     Database       REXXSQL_USERNAME REXXSQL_PASSWORD REXXSQL_DATABASE
  11.  *     ----------------------------------------------------------------
  12.  *     ORACLE         SCOTT            TIGER
  13.  *     SQLAnyWhere    dba              sql              SADEMO
  14.  *     DB2/2          userid           password         SAMPLE
  15.  *     mySQL                                            REXXSQL
  16.  *     mSQL                                             REXXSQL
  17.  *     ODBC(Access)                                     REXXSQL
  18.  * 2.  Run this Rexx/SQL program with a parameter of "setup". This creates
  19.  *     the two test tables; RX_EMP and RX_DEPT.
  20.  * 3.  Run this Rexx/SQL program with no parameters. This runs the complete
  21.  *     test suite. Alternately, you can run each individual test by specifying
  22.  *     its name as the only parameter. The valid values are specified below
  23.  * in the variable "exercise".
  24. */
  25. Trace o
  26. exercise = 'connections describe fetch command placemarker transaction info errors'
  27. If initialise() Then Exit 1
  28. Parse Arg test .
  29. If test = '' Then
  30.   Do i = 1 To Words(exercise)
  31.     Interpret Call Word(exercise,i) 
  32.   End
  33. Else
  34.   Do
  35.     If Datatype(test,'NUM') Then Interpret Call Word(exercise,test)
  36.     Else Interpret Call test 
  37.   End
  38. Call finalise
  39. Return
  40.  
  41. /*-----------------------------------------------------------------*/
  42. initialise:
  43. dll.unix='./rexxsql.rxlib'
  44. dll.os2='REXXSQL'
  45. dll.win32='REXXSQL'
  46. dll.windowsnt='REXXSQL'
  47. dll.windows95='REXXSQL'
  48. Parse Source int_os method .
  49. If int_os = 'OS/2' Then int_os = 'OS2'; Else int_os = Translate(int_os)
  50. If method = 'COMMAND' Then
  51.    Do
  52.      rc = RXFuncAdd('SQLLoadFuncs',dll.int_os,'SQLLoadFuncs')
  53.      Call SqlLoadFuncs
  54.      dll = 'YES'
  55.    End
  56. version = sqlvariable('VERSION')
  57. say version
  58. Parse Var version . . . . . os db .
  59. db = Translate(db)
  60. select
  61.   when os = 'UNIX' Then envname = 'SYSTEM'
  62.   when os = 'WIN32' Then envname = 'ENVIRONMENT'
  63.   when os = 'OS/2' Then envname = 'OS2ENVIRONMENT'
  64.   otherwise Say 'Unsupported platform'
  65. end
  66. sqlconnect.1 = Value('REXXSQL_USERNAME',,envname)
  67. sqlconnect.2 = Value('REXXSQL_PASSWORD',,envname)
  68. sqlconnect.3 = Value('REXXSQL_DATABASE',,envname)
  69. sqlconnect.4 = Value('REXXSQL_SERVER'  ,,envname)
  70. columnnames_emp  = 'empid deptno mgrid empname startdt enddt salary dbname'
  71. columnnames_dept = 'deptno deptname dbname'
  72. stringdatatypes_empid.oracle         = 'NUMBER'
  73. stringdatatypes_deptno.oracle        = 'NUMBER'
  74. stringdatatypes_empid.msql           = 'INT'
  75. stringdatatypes_deptno.msql          = 'INT'
  76. stringdatatypes_empid.mysql          = 'INT'
  77. stringdatatypes_deptno.mysql         = 'INT'
  78. stringdatatypes_empid.sybase_sql_anywhere    = 'SMALLINT'
  79. stringdatatypes_deptno.sybase_sql_anywhere   = 'SMALLINT'
  80. stringdatatypes_empid.sqlanywhere    = 'SMALLINT'
  81. stringdatatypes_deptno.sqlanywhere   = 'SMALLINT'
  82. stringdatatypes_empid.db2            = 'SMALLINT'
  83. stringdatatypes_deptno.db2           = 'SMALLINT'
  84. /*
  85.  * ODBC datatypes have to be specified AFTER a connection is made to a
  86.  * database.
  87.  */
  88. Return 0
  89.  
  90. /*-----------------------------------------------------------------*/
  91. finalise:
  92. If dll = 'YES' Then Call SqlDropFuncs
  93. Return
  94.  
  95. /*-----------------------------------------------------------------*/
  96. connect: Procedure Expose sqlca. sqlconnect.
  97. Parse Arg id .
  98. If sqlconnect(id,sqlconnect.1,sqlconnect.2,sqlconnect.3,sqlconnect.4) < 0 Then Abort('connect')
  99. Say 'connect: succeeded for <'id'> <'sqlconnect.1'> <'sqlconnect.2'> <'sqlconnect.3'> <'sqlconnect.4'>'
  100. Return
  101.  
  102. /*-----------------------------------------------------------------*/
  103. disconnect: Procedure Expose sqlca.
  104. Parse Arg id
  105. If sqldisconnect(id) < 0 Then Abort('disconnect')
  106. Say 'disconnect: succeeded for <'id'>'
  107. Return
  108.  
  109. /*-----------------------------------------------------------------*/
  110. setup: Procedure Expose sqlca. sqlconnect. db columnnames_emp columnnames_dept 
  111.  
  112. Say Copies('*',20)
  113. Say 'setup: Creating test tables...'
  114. Say Copies('*',20)
  115. Call connect 'c1'
  116. /*
  117.  * For ODBC we need to determine the database we are connecting to so we
  118.  * can use this to specify the datatypes that it can use
  119.  */
  120. dbcon = Translate(sqlgetinfo('c1','DBMSNAME'))
  121. If db = 'ODBC' Then db = Translate(dbcon)
  122.  
  123. src = "'"||dbcon||"'"
  124. Call setdatatypes
  125. create1 = 'create table RX_EMP ('
  126. Do i = 1 To Words(columnnames_emp)
  127.   create1 = create1 Word(columnnames_emp,i) columntypes_emp.db.i
  128. End
  129. create1 = create1 ')'
  130. Call create_test_table 'RX_EMP' create1
  131.  
  132. create1 = 'create table RX_DEPT ('
  133. Do i = 1 To Words(columnnames_dept)
  134.   create1 = create1 Word(columnnames_dept,i) columntypes_dept.db.i
  135. End
  136. create1 = create1 ')'
  137. Call create_test_table 'RX_DEPT' create1
  138. Do i = 1 To columndata_emp.db.0
  139.    c1 = "insert into RX_EMP values(",
  140.         Strip(Substr(columndata_emp.db.i,1,5)) ',',
  141.         Strip(Substr(columndata_emp.db.i,6,5)) ',',
  142.         Strip(Substr(columndata_emp.db.i,11,5)) ',',
  143.         Strip(Substr(columndata_emp.db.i,16,32)) ',',
  144.         Strip(Substr(columndata_emp.db.i,49,12)) ',',
  145.         Strip(Substr(columndata_emp.db.i,61,12)) ',',
  146.         Strip(Substr(columndata_emp.db.i,73,13)) ',' ,
  147.         src ")"
  148.    If sqlcommand('c1',c1) < 0 Then Abort('setup: inserting into RX_EMP table')
  149.    If sqlvariable('SUPPORTSDMLROWCOUNT') = 1 Then Say 'setup:' sqlca.rowcount 'row(s) inserted successfully'
  150.    Else Say 'setup: setting of SQLCA.ROWCOUNT for DML not supported; insert succeeded'
  151. End
  152. Do i = 1 To columndata_dept.db.0
  153.    c2 = "insert into RX_DEPT values(",
  154.         Strip(Substr(columndata_dept.db.i,1,5)) ',',
  155.         Strip(Substr(columndata_dept.db.i,6,52)) ',',
  156.         src ")"
  157.    If sqlcommand('c2',c2) < 0 Then Abort('setup: inserting into RX_DEPT table')
  158.    If sqlvariable('SUPPORTSDMLROWCOUNT') = 1 Then Say 'setup:' sqlca.rowcount 'row(s) inserted successfully'
  159.    Else Say 'setup: setting of SQLCA.ROWCOUNT for DML not supported; insert succeeded'
  160. End
  161. If sqlcommit() < 0 Then Abort('setup: commiting')
  162. Call disconnect 'c1'
  163. Return
  164.  
  165. /*-----------------------------------------------------------------*/
  166. setdatatypes:
  167.  
  168. /*  table definitions for Oracle */
  169. columntypes_emp.oracle.1 = 'number(5) not null,'
  170. columntypes_emp.oracle.2 = 'number(5) not null,'
  171. columntypes_emp.oracle.3 = 'number(5) not null,'
  172. columntypes_emp.oracle.4 = 'varchar2(30) not null,'
  173. columntypes_emp.oracle.5 = 'date,'
  174. columntypes_emp.oracle.6 = 'date,'
  175. columntypes_emp.oracle.7 = 'number(10,2) not null,'
  176. columntypes_emp.oracle.8 = 'varchar2(30)'
  177. /*                                  1         2         3          4        5         6         7         8         9        10         11       12 */
  178. /*                         123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  179. /*                         [---][---][---][-------------------------------][----------][----------][-----------]                                    */
  180. columndata_emp.oracle.1 = "    1   10    0'Joe Bloggs'                     '26-JAN-96' NULL               556.22"
  181. columndata_emp.oracle.2 = "    2   10    1'Mary Jones'                     '26-FEB-91' '26-JAN-96'        202.04"
  182. columndata_emp.oracle.3 = "    3   20    1'Steve Brown'                    '04-MAY-95' NULL               345.00"
  183. columndata_emp.oracle.0 = 3
  184.  
  185. columntypes_dept.oracle.1 = 'number(5) not null,'
  186. columntypes_dept.oracle.2 = 'varchar2(50) not null,'
  187. columntypes_dept.oracle.3 = 'varchar2(30)'
  188. /*                                   1         2         3          4        5         6         7         8         9        10         11       12 */
  189. /*                          123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  190. /*                          [---][------------------------------------------------------------]                                                      */
  191. columndata_dept.oracle.1 = "   10'Department 10'                                               "
  192. columndata_dept.oracle.2 = "   20'Department 20'                                               "
  193. columndata_dept.oracle.0 = 2
  194.  
  195. /*  table definitions for mSQL */
  196. columntypes_emp.msql.1 = 'int primary key,'
  197. columntypes_emp.msql.2 = 'int not null,'
  198. columntypes_emp.msql.3 = 'int not null,'
  199. columntypes_emp.msql.4 = 'char(30) not null,'
  200. columntypes_emp.msql.5 = 'char(9),'
  201. columntypes_emp.msql.6 = 'char(9),'
  202. columntypes_emp.msql.7 = 'real not null,'
  203. columntypes_emp.msql.8 = 'char(30)'
  204. /*                                1         2         3          4        5         6         7         8         9        10         11       12 */
  205. /*                       123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  206. /*                       [---][---][---][-------------------------------][----------][----------][-----------]                                    */
  207. columndata_emp.msql.1 = "    1   10    0'Joe Bloggs'                     '26-JAN-96' NULL               556.22"
  208. columndata_emp.msql.2 = "    2   10    1'Mary Jones'                     '26-FEB-91' '26-JAN-96'        202.04"
  209. columndata_emp.msql.3 = "    3   20    1'Steve Brown'                    '04-MAY-95' NULL               345.00"
  210. columndata_emp.msql.0 = 3
  211.  
  212. columntypes_dept.msql.1 = 'int not null,'
  213. columntypes_dept.msql.2 = 'char(50) not null,'
  214. columntypes_dept.msql.3 = 'char(30)'
  215. /*                                 1         2         3          4        5         6         7         8         9        10         11       12 */
  216. /*                        123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  217. /*                        [---][------------------------------------------------------------]                                                      */
  218. columndata_dept.msql.1 = "   10'Department 10'                                               "
  219. columndata_dept.msql.2 = "   20'Department 20'                                               "
  220. columndata_dept.msql.0 = 2
  221.  
  222. /*  table definitions for mySQL */
  223. columntypes_emp.mysql.1 = 'int primary key,'
  224. columntypes_emp.mysql.2 = 'int not null,'
  225. columntypes_emp.mysql.3 = 'int not null,'
  226. columntypes_emp.mysql.4 = 'char(30) not null,'
  227. columntypes_emp.mysql.5 = 'date,'
  228. columntypes_emp.mysql.6 = 'date,'
  229. columntypes_emp.mysql.7 = 'decimal(9,2) not null,'
  230. columntypes_emp.mysql.8 = 'char(30)'
  231. /*                                 1         2         3          4        5         6         7         8         9        10         11       12 */
  232. /*                        123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  233. /*                        [---][---][---][-------------------------------][----------][----------][-----------]                                    */
  234. columndata_emp.mysql.1 = "    1   10    0'Joe Bloggs'                     '19960126'  NULL               556.22"
  235. columndata_emp.mysql.2 = "    2   10    1'Mary Jones'                     '19910226'  '19960126'         202.04"
  236. columndata_emp.mysql.3 = "    3   20    1'Steve Brown'                    '19950504'  NULL               345.00"
  237. columndata_emp.mysql.0 = 3
  238.  
  239. columntypes_dept.mysql.1 = 'int not null,'
  240. columntypes_dept.mysql.2 = 'char(50) not null,'
  241. columntypes_dept.mysql.3 = 'char(30)'
  242. /*                                  1         2         3          4        5         6         7         8         9        10         11       12 */
  243. /*                         123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  244. /*                         [---][------------------------------------------------------------]                                                      */
  245. columndata_dept.mysql.1 = "   10'Department 10'                                               "
  246. columndata_dept.mysql.2 = "   20'Department 20'                                               "
  247. columndata_dept.mysql.0 = 2
  248.  
  249. /*  table definitions for Sybase_SQL_Anywhere */
  250. columntypes_emp.Sybase_SQL_Anywhere.1 = 'smallint not null,'
  251. columntypes_emp.Sybase_SQL_Anywhere.2 = 'smallint not null,'
  252. columntypes_emp.Sybase_SQL_Anywhere.3 = 'smallint not null,'
  253. columntypes_emp.Sybase_SQL_Anywhere.4 = 'varchar(30) not null,'
  254. columntypes_emp.Sybase_SQL_Anywhere.5 = 'date,'
  255. columntypes_emp.Sybase_SQL_Anywhere.6 = 'date,'
  256. columntypes_emp.Sybase_SQL_Anywhere.7 = 'money not null,'
  257. columntypes_emp.Sybase_SQL_Anywhere.8 = 'varchar(30)'
  258. columntypes_emp.sqlanywhere.1 = 'smallint not null,'
  259. columntypes_emp.sqlanywhere.2 = 'smallint not null,'
  260. columntypes_emp.sqlanywhere.3 = 'smallint not null,'
  261. columntypes_emp.sqlanywhere.4 = 'varchar(30) not null,'
  262. columntypes_emp.sqlanywhere.5 = 'date,'
  263. columntypes_emp.sqlanywhere.6 = 'date,'
  264. columntypes_emp.sqlanywhere.7 = 'money not null,'
  265. columntypes_emp.sqlanywhere.8 = 'varchar(30)'
  266. /*                                       1         2         3          4        5         6         7         8         9        10         11       12 */
  267. /*                              123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  268. /*                              [---][---][---][-------------------------------][----------][----------][-----------]                                    */
  269. columndata_emp.Sybase_SQL_Anywhere.1 = "    1   10    0'Joe Bloggs'                     '19960126'  NULL               556.22"
  270. columndata_emp.Sybase_SQL_Anywhere.2 = "    2   10    1'Mary Jones'                     '19910226'  '19960126'         202.04"
  271. columndata_emp.Sybase_SQL_Anywhere.3 = "    3   20    1'Steve Brown'                    '19950504'  NULL               345.00"
  272. columndata_emp.Sybase_SQL_Anywhere.0 = 3
  273.  
  274. columntypes_dept.Sybase_SQL_Anywhere.1 = 'smallint not null,'
  275. columntypes_dept.Sybase_SQL_Anywhere.2 = 'char(50) not null,'
  276. columntypes_dept.Sybase_SQL_Anywhere.3 = 'char(30)'
  277. /*                                        1         2         3          4        5         6         7         8         9        10         11       12 */
  278. /*                               123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  279. /*                               [---][------------------------------------------------------------]                                                      */
  280. columndata_dept.Sybase_SQL_Anywhere.1 = "   10'Department 10'                                               "
  281. columndata_dept.Sybase_SQL_Anywhere.2 = "   20'Department 20'                                               "
  282. columndata_dept.Sybase_SQL_Anywhere.0 = 2
  283.  
  284. columndata_emp.sqlanywhere.1 = "    1   10    0'Joe Bloggs'                     '19960126'  NULL               556.22"
  285. columndata_emp.sqlanywhere.2 = "    2   10    1'Mary Jones'                     '19910226'  '19960126'         202.04"
  286. columndata_emp.sqlanywhere.3 = "    3   20    1'Steve Brown'                    '19950504'  NULL               345.00"
  287. columndata_emp.sqlanywhere.0 = 3
  288.  
  289. columntypes_dept.sqlanywhere.1 = 'smallint not null,'
  290. columntypes_dept.sqlanywhere.2 = 'char(50) not null,'
  291. columntypes_dept.sqlanywhere.3 = 'char(30)'
  292. /*                                        1         2         3          4        5         6         7         8         9        10         11       12 */
  293. /*                               123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  294. /*                               [---][------------------------------------------------------------]                                                      */
  295. columndata_dept.sqlanywhere.1 = "   10'Department 10'                                               "
  296. columndata_dept.sqlanywhere.2 = "   20'Department 20'                                               "
  297. columndata_dept.sqlanywhere.0 = 2
  298.  
  299. /*  table definitions for DB2 */
  300. columntypes_emp.db2.1 = 'smallint not null,'
  301. columntypes_emp.db2.2 = 'smallint not null,'
  302. columntypes_emp.db2.3 = 'smallint not null,'
  303. columntypes_emp.db2.4 = 'varchar(30) not null,'
  304. columntypes_emp.db2.5 = 'date,'
  305. columntypes_emp.db2.6 = 'date,'
  306. columntypes_emp.db2.7 = 'decimal(8,2) not null,'
  307. columntypes_emp.db2.8 = 'varchar(30)'
  308. /*                               1         2         3          4        5         6         7         8         9        10         11       12 */
  309. /*                      123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  310. /*                      [---][---][---][-------------------------------][----------][----------][-----------]                                    */
  311. columndata_emp.db2.1 = "    1   10    0'Joe Bloggs'                     '1996-01-26'NULL               556.22"
  312. columndata_emp.db2.2 = "    2   10    1'Mary Jones'                     '1991-02-26''1996-01-26'       202.04"
  313. columndata_emp.db2.3 = "    3   20    1'Steve Brown'                    '1995-05-04'NULL               345.00"
  314. columndata_emp.db2.0 = 3
  315.  
  316. columntypes_dept.db2.1 = 'smallint not null,'
  317. columntypes_dept.db2.2 = 'char(50) not null,'
  318. columntypes_dept.db2.3 = 'varchar(30)'
  319. /*                                1         2         3          4        5         6         7         8         9        10         11       12 */
  320. /*                       123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  321. /*                       [---][------------------------------------------------------------]                                                      */
  322. columndata_dept.db2.1 = "   10'Department 10'                                               "
  323. columndata_dept.db2.2 = "   20'Department 20'                                               "
  324. columndata_dept.db2.0 = 2
  325.  
  326. /*  table definitions for ACCESS */
  327. columntypes_emp.access.1 = 'byte not null,'
  328. columntypes_emp.access.2 = 'byte not null,'
  329. columntypes_emp.access.3 = 'byte not null,'
  330. columntypes_emp.access.4 = 'char(30) not null,'
  331. columntypes_emp.access.5 = 'datetime,'
  332. columntypes_emp.access.6 = 'datetime,'
  333. columntypes_emp.access.7 = 'currency not null,'
  334. columntypes_emp.access.8 = 'char(30)'
  335. /*                                  1         2         3          4        5         6         7         8         9        10         11       12 */
  336. /*                         123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  337. /*                         [---][---][---][-------------------------------][----------][----------][-----------]                                    */
  338. columndata_emp.access.1 = "    1   10    0'Joe Bloggs'                     '26/01/1996'NULL               556.22"
  339. columndata_emp.access.2 = "    2   10    1'Mary Jones'                     '26/02/1991''26/01/1996'       202.04"
  340. columndata_emp.access.3 = "    3   20    1'Steve Brown'                    '04/05/1995'NULL               345.00"
  341. columndata_emp.access.0 = 3
  342.  
  343. columntypes_dept.access.1 = 'byte not null,'
  344. columntypes_dept.access.2 = 'char(50) not null,'
  345. columntypes_dept.access.3 = 'char(30)'
  346. /*                                   1         2         3          4        5         6         7         8         9        10         11       12 */
  347. /*                          123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  348. /*                          [---][------------------------------------------------------------]                                                      */
  349. columndata_dept.access.1 = "   10'Department 10'                                               "
  350. columndata_dept.access.2 = "   20'Department 20'                                               "
  351. columndata_dept.access.0 = 2
  352.  
  353. /*  table definitions for ACCESS */
  354. columntypes_emp.dbase.1 = 'numeric not null,'
  355. columntypes_emp.dbase.2 = 'numeric not null,'
  356. columntypes_emp.dbase.3 = 'numeric not null,'
  357. columntypes_emp.dbase.4 = 'char(30) not null,'
  358. columntypes_emp.dbase.5 = 'date,'
  359. columntypes_emp.dbase.6 = 'date,'
  360. columntypes_emp.dbase.7 = 'numeric not null,'
  361. columntypes_emp.dbase.8 = 'char(30)'
  362. /*                                 1         2         3          4        5         6         7         8         9        10         11       12 */
  363. /*                        123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  364. /*                        [---][---][---][-------------------------------][----------][----------][-----------]                                    */
  365. columndata_emp.dbase.1 = "    1   10    0'Joe Bloggs'                     '26/01/1996'NULL               556.22"
  366. columndata_emp.dbase.2 = "    2   10    1'Mary Jones'                     '26/02/1991''26/01/1996'       202.04"
  367. columndata_emp.dbase.3 = "    3   20    1'Steve Brown'                    '04/05/1995'NULL               345.00"
  368. columndata_emp.dbase.0 = 3
  369.  
  370. columntypes_dept.dbase.1 = 'numeric not null,'
  371. columntypes_dept.dbase.2 = 'char(50) not null,'
  372. columntypes_dept.dbase.3 = 'char(30)'
  373. /*                                  1         2         3          4        5         6         7         8         9        10         11       12 */
  374. /*                         123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  375. /*                         [---][------------------------------------------------------------]                                                      */
  376. columndata_dept.dbase.1 = "   10'Department 10'                                               "
  377. columndata_dept.dbase.2 = "   20'Department 20'                                               "
  378. columndata_dept.dbase.0 = 2
  379. Return
  380.  
  381. /*-----------------------------------------------------------------*/
  382. setbindtypes:
  383. stringdatatypes_empid.access         = 'BYTE'
  384. stringdatatypes_deptno.access        = 'BYTE'
  385. stringdatatypes_empid.dbase          = 'NUMERIC'
  386. stringdatatypes_deptno.dbase         = 'NUMERIC'
  387. Return
  388.  
  389. /*-----------------------------------------------------------------*/
  390. create_test_table: Procedure Expose sqlca.
  391. Parse Arg table_name create_string
  392. rc = sqlcommand('c1','drop table' table_name) 
  393. If sqlcommand('c1',create_string) < 0 Then Abort('setup: creating' table_name 'table')
  394. Say 'setup:' table_name 'created successfully'
  395. Return
  396.  
  397. /*-----------------------------------------------------------------*/
  398. connections: Procedure Expose sqlca. sqlconnect.
  399. Say Copies('*',20)
  400. Say 'Testing multiple connections/disconnections...'
  401. Say Copies('*',20)
  402. Call connect 'c1'
  403. Call connect 'c2'
  404. Call connect 'c3'
  405. Call disconnect 'c1'
  406. Call disconnect 'c2'
  407. Call disconnect 'c3'
  408. Return
  409.  
  410. /*-----------------------------------------------------------------*/
  411. describe: Procedure Expose sqlca. sqlconnect. db os
  412. Say Copies('*',20)
  413. Say 'Testing statement descriptions...'
  414. Say Copies('*',20)
  415. If db = 'ORACLE' & os = 'OS/2' Then
  416.   Do
  417.     query1 = 'select * from RX_EMP order by empid'
  418. /*  query1 = 'select empid,empname from RX_EMP'*/
  419. /*  query1 = 'select * from RX_EMP a, RX_DEPT b where a.deptno = b.deptno'*/
  420.     Say Copies('*',30)
  421.     Say 'The OS/2 port of Oracle (at least 7.0.xx) does not'
  422.     Say 'correctly describe the following statement:'
  423.     Say ' select * from RX_EMP'
  424.     Say Copies('*',30)
  425.   End
  426. Else
  427.   query1 = 'select * from RX_EMP'
  428. Call connect 'c1'
  429. If sqlgetinfo('c1','DESCRIBECOLUMNS','desc.') < 0 Then Abort('describe: getting describe columns')
  430. Do i = 1 To desc.0
  431.    width.i = Length(desc.i)
  432. End
  433. Say 'describe: Describing <'|| query1 ||'>'
  434. If sqlprepare('p1',query1) < 0 Then Abort('describe: preparing')
  435. If sqldescribe('p1') < 0 Then Abort('describe: describing')
  436. col = desc.1
  437. num_rows = p1.column.col.0
  438. Do i = 1 To num_rows
  439.    Do j = 1 To desc.0
  440.       col = desc.j
  441.       col_val = p1.column.col.i
  442.       if Length(col_val) > width.j Then width.j = Length(col_val)
  443.    End
  444. End
  445. line = ''
  446. line_len = 0
  447. Do i = 1 To desc.0
  448.    line = line Left(desc.i,width.i)
  449.    line_len = line_len + 1 + width.i
  450. End
  451. Say line
  452. Say Copies('-',line_len)
  453. Do i = 1 To num_rows
  454.    line = ''
  455.    Do j = 1 To desc.0
  456.       col = desc.j
  457.       line = line Left(p1.column.col.i,width.j)
  458.    End
  459.    Say line
  460. End
  461. If sqldispose('p1') < 0 Then Abort('describe: disposing')
  462. Call disconnect 'c1'
  463. Return
  464.  
  465. /*-----------------------------------------------------------------*/
  466. fetch: Procedure Expose sqlca. sqlconnect. columnnames_emp columnnames_dept db os
  467. Say Copies('*',20)
  468. Say 'Testing sqlprepare/sqlopen/sqlfetch...'
  469. Say Copies('*',20)
  470. If db = 'ORACLE' & os = 'OS/2' Then
  471.   Do
  472.     query1 = 'select * from RX_EMP order by empid'
  473. /*  query1 = 'select empid,empname from RX_EMP'*/
  474. /*  query1 = 'select * from RX_EMP a, RX_DEPT b where a.deptno = b.deptno'*/
  475.     Say Copies('*',30)
  476.     Say 'The OS/2 port of Oracle (at least 7.0.xx) does not'
  477.     Say 'correctly describe the following statement:'
  478.     Say ' select * from RX_EMP'
  479.     Say Copies('*',30)
  480.   End
  481. Else
  482.   query1 = 'select * from RX_EMP'
  483. Call connect 'c1'
  484. rc = sqlvariable('NULLSTRINGOUT','<null>')
  485. Say 'fetch: Fetching for <'|| query1 ||'>'
  486. If sqlprepare('p1',query1) < 0 Then Abort('fetch: preparing')
  487. If sqlopen('p1') < 0 Then Abort('fetch: opening')
  488. Do Forever
  489.    rc = sqlfetch('p1')
  490.    If rc < 0 then Abort('fetch: fetching')
  491.    If rc = 0 Then Leave
  492.    line = ''
  493.    Do j = 1 To Words(columnnames_emp)
  494.       col = Translate(Word(columnnames_emp,j))
  495.       line = line p1.col
  496.    End
  497.    Say line
  498. End
  499. If sqlclose('p1') < 0 Then Abort('fetch: closing')
  500. If sqldispose('p1') < 0 Then Abort('fetch: disposing')
  501. Call disconnect 'c1'
  502. Return
  503.  
  504. /*-----------------------------------------------------------------*/
  505. command: Procedure Expose sqlca. sqlconnect. columnnames_emp columnnames_dept
  506. Say Copies('*',20)
  507. Say 'Testing sqlcommand...'
  508. Say Copies('*',20)
  509. query1 = "select * from RX_EMP"
  510. Call connect 'c1'
  511. rc = sqlvariable('NULLSTRINGOUT','<null>')
  512. Say 'command: <'|| query1 ||'>'
  513. If sqlcommand('p1',query1) < 0 Then Abort('command: executing')
  514. Say 'command:' sqlca.rowcount 'row(s) retrieved successfully'
  515. col = Translate(Word(columnnames_emp,1))
  516. num_rows = p1.col.0
  517. Do i = 1 To num_rows
  518.    line = ''
  519.    Do j = 1 To Words(columnnames_emp)
  520.       col = Translate(Word(columnnames_emp,j))
  521.       line = line p1.col.i
  522.    End
  523.    Say line
  524. End
  525. Call disconnect 'c1'
  526. Return
  527.  
  528. /*-----------------------------------------------------------------*/
  529. placemarker: Procedure Expose sqlca. sqlconnect. os db columnnames_emp columnnames_dept stringdatatypes_empid. stringdatatypes_deptno.
  530. Say Copies('*',20)
  531. Say 'Testing sqlcommand with placemarkers...'
  532. Say Copies('*',20)
  533. If sqlvariable('SUPPORTSPLACEMARKERS') = 0 Then
  534.   Do
  535.      Say db 'does not support the use of placemarkers in queries. This test ignored.'
  536.      Return
  537.   End
  538. query1 = "select * from RX_EMP where empid = ? and deptno = ?"
  539. Call connect 'c1'
  540. dbcon = sqlgetinfo('c1','DBMSNAME')
  541. If db = 'ODBC' Then db = Translate(dbcon)
  542. Call setbindtypes
  543. rc = sqlvariable('NULLSTRINGOUT','<null>')
  544. rc = sqlvariable('STANDARDPLACEMARKERS',1)
  545. Say 'placemarker: (normal): <'|| query1 ||'>'
  546. If sqlcommand('p1',query1,stringdatatypes_empid.db,1,stringdatatypes_deptno.db,10) < 0 Then Abort('placemarker: (normal) executing')
  547. col = Translate(Word(columnnames_emp,1))
  548. num_rows = p1.col.0
  549. Do i = 1 To num_rows
  550.    line = ''
  551.    Do j = 1 To Words(columnnames_emp)
  552.       col = Translate(Word(columnnames_emp,j))
  553.       line = line p1.col.i
  554.    End
  555.    Say line
  556. End
  557. Say 'placemarker:  (array): <'|| query1 ||'>'
  558. dt.0 = 2
  559. dt.1 = stringdatatypes_empid.db
  560. dt.2 = stringdatatypes_deptno.db
  561. dv.0 = 2
  562. dv.1 = 1
  563. dv.2 = 10
  564. If sqlcommand('p1',query1,'dt.','dv.') < 0 Then Abort('placemarker: (array) executing')
  565. col = Translate(Word(columnnames_emp,1))
  566. num_rows = p1.col.0
  567. Do i = 1 To num_rows
  568.    line = ''
  569.    Do j = 1 To Words(columnnames_emp)
  570.       col = Translate(Word(columnnames_emp,j))
  571.       line = line p1.col.i
  572.    End
  573.    Say line
  574. End
  575. Say 'placemarker:   (file): <'|| query1 ||'>'
  576. ei_file = 'empid.tmp'
  577. dn_file = 'deptno.tmp'
  578. If os = 'UNIX' Then
  579.   Do
  580.     Address System 'rm' ei_file
  581.     Address System 'rm' dn_file
  582.   End
  583. Else
  584.   Do
  585.     Address System 'del' ei_file
  586.     Address System 'del' dn_file
  587.   End
  588. rc = Charout(ei_file,,1)
  589. rc = Charout(ei_file,'1')
  590. rc = Charout(ei_file)
  591. rc = Charout(dn_file,,1)
  592. rc = Charout(dn_file,'10')
  593. rc = Charout(dn_file)
  594. dt.0 = 2
  595. dt.1 = 'FILE:'||stringdatatypes_empid.db
  596. dt.2 = 'FILE:'||stringdatatypes_deptno.db
  597. dv.0 = 2
  598. dv.1 = ei_file
  599. dv.2 = dn_file
  600. If sqlcommand('p1',query1,'dt.','dv.') < 0 Then Abort('placemarker: (file) executing')
  601. col = Translate(Word(columnnames_emp,1))
  602. num_rows = p1.col.0
  603. Do i = 1 To num_rows
  604.    line = ''
  605.    Do j = 1 To Words(columnnames_emp)
  606.       col = Translate(Word(columnnames_emp,j))
  607.       line = line p1.col.i
  608.    End
  609.    Say line
  610. End
  611. If db = 'ORACLE' Then
  612.   Do
  613.    rc = sqlvariable('STANDARDPLACEMARKERS',0)
  614.    query1 = "select * from RX_EMP where empid = :1 and deptno = :2"
  615.    Say 'placemarker: (oracle-normal-number): <'|| query1 ||'>'
  616.    If sqlcommand('p1',query1,'#',1,10) < 0 Then Abort('placemarker: (oracle-normal-number) executing')
  617.    col = Translate(Word(columnnames_emp,1))
  618.    num_rows = p1.col.0
  619.    Do i = 1 To num_rows
  620.       line = ''
  621.       Do j = 1 To Words(columnnames_emp)
  622.          col = Translate(Word(columnnames_emp,j))
  623.          line = line p1.col.i
  624.       End
  625.       Say line
  626.    End
  627.    Say 'placemarker:  (oracle-array-number): <'|| query1 ||'>'
  628.    dv.0 = 2
  629.    dv.1 = 1
  630.    dv.2 = 10
  631.    If sqlcommand('p1',query1,'.','dv.') < 0 Then Abort('placemarker: (oracle-array-number) executing')
  632.    col = Translate(Word(columnnames_emp,1))
  633.    num_rows = p1.col.0
  634.    Do i = 1 To num_rows
  635.       line = ''
  636.       Do j = 1 To Words(columnnames_emp)
  637.          col = Translate(Word(columnnames_emp,j))
  638.          line = line p1.col.i
  639.       End
  640.       Say line
  641.    End
  642.    query1 = "select * from RX_EMP where empid = :empid and deptno = :deptno"
  643.    Say 'placemarker: (oracle-normal-name): <'|| query1 ||'>'
  644.    If sqlcommand('p1',query1,':empid',1,':deptno',10) < 0 Then Abort('placemarker: (oracle-normal-name) executing')
  645.    col = Translate(Word(columnnames_emp,1))
  646.    num_rows = p1.col.0
  647.    Do i = 1 To num_rows
  648.       line = ''
  649.       Do j = 1 To Words(columnnames_emp)
  650.          col = Translate(Word(columnnames_emp,j))
  651.          line = line p1.col.i
  652.       End
  653.       Say line
  654.    End
  655.    Say 'placemarker:  (oracle-array-name): <'|| query1 ||'>'
  656.    dn.0 = 2
  657.    dn.1 = ':empid'
  658.    dn.2 = ':deptno'
  659.    dv.0 = 2
  660.    dv.1 = 1
  661.    dv.2 = 10
  662.    If sqlcommand('p1',query1,'.','dn.','dv.') < 0 Then Abort('placemarker: (oracle-array-name) executing')
  663.    col = Translate(Word(columnnames_emp,1))
  664.    num_rows = p1.col.0
  665.    Do i = 1 To num_rows
  666.       line = ''
  667.       Do j = 1 To Words(columnnames_emp)
  668.          col = Translate(Word(columnnames_emp,j))
  669.          line = line p1.col.i
  670.       End
  671.       Say line
  672.    End
  673.   End
  674. Call disconnect 'c1'
  675. Return
  676.  
  677. /*-----------------------------------------------------------------*/
  678. transaction: Procedure Expose sqlca. sqlconnect. db columnnames_emp columnnames_dept stringdatatypes_empid. stringdatatypes_deptno.
  679. Say Copies('*',20)
  680. Say 'Testing transactions and sqlexecute...'
  681. Say Copies('*',20)
  682. select1 = "select * from RX_DEPT"
  683. insert1 = "insert into RX_DEPT values (100,'Department 100 - new','dummy')"
  684. insert2 = "insert into RX_DEPT values (200,'Department 200 - new','dummy')"
  685. Call connect 'c1'
  686. rc = sqlvariable('NULLSTRINGOUT','<null>')
  687. Say 'transaction: Contents of RX_DEPT before INSERTs'
  688. If sqlcommand('q1',select1) < 0 Then Abort('transaction: executing')
  689. col = Translate(Word(columnnames_dept,1))
  690. num_rows = q1.col.0
  691. Do i = 1 To num_rows
  692.    line = ''
  693.    Do j = 1 To Words(columnnames_dept)
  694.       col = Translate(Word(columnnames_dept,j))
  695.       line = line q1.col.i
  696.    End
  697.    Say line
  698. End
  699. Say 'transaction: Inserting 2 rows into RX_DEPT'
  700. If sqlcommand('q1',insert1) < 0 Then Abort('transaction: executing')
  701. If sqlvariable('SUPPORTSDMLROWCOUNT') = 1 Then Say 'transaction:' sqlca.rowcount 'row(s) inserted successfully'
  702. Else Say 'transaction: setting of SQLCA.ROWCOUNT for DML not supported; insert succeeded'
  703. If sqlprepare('q2',insert2) < 0 Then Abort('transaction: preparing')
  704. If sqlexecute('q2') < 0 Then Abort('transaction: executing')
  705. If sqlvariable('SUPPORTSDMLROWCOUNT') = 1 Then Say 'transaction:' sqlca.rowcount 'row(s) inserted successfully'
  706. Else Say 'transaction: setting of SQLCA.ROWCOUNT for DML not supported; insert succeeded'
  707. If sqldispose('q2') < 0 Then Abort('transaction: disposing')
  708. Say 'transaction: Contents of RX_DEPT after INSERTs'
  709. If sqlcommand('q1',select1) < 0 Then Abort('transaction: executing')
  710. col = Translate(Word(columnnames_dept,1))
  711. num_rows = q1.col.0
  712. Do i = 1 To num_rows
  713.    line = ''
  714.    Do j = 1 To Words(columnnames_dept)
  715.       col = Translate(Word(columnnames_dept,j))
  716.       line = line q1.col.i
  717.    End
  718.    Say line
  719. End
  720. Say 'transaction: Rolling back transaction'
  721. If sqlgetinfo('c1','SUPPORTSTRANSACTIONS') = 0 Then
  722.    Say '***' db 'does not support the use of transactions. Rollback is ignored.'
  723. If sqlrollback() < 0 Then Abort('transaction: rolling back')
  724. Say 'transaction: Contents of RX_DEPT after ROLLBACK'
  725. If sqlcommand('q1',select1) < 0 Then Abort('transaction: executing')
  726. col = Translate(Word(columnnames_dept,1))
  727. num_rows = q1.col.0
  728. Do i = 1 To num_rows
  729.    line = ''
  730.    Do j = 1 To Words(columnnames_dept)
  731.       col = Translate(Word(columnnames_dept,j))
  732.       line = line q1.col.i
  733.    End
  734.    Say line
  735. End
  736. Call disconnect 'c1'
  737. Return
  738.  
  739. /*-----------------------------------------------------------------*/
  740. errors: Procedure Expose sqlca. sqlconnect. db columnnames_emp columnnames_dept stringdatatypes_empid. stringdatatypes_deptno.
  741. Say Copies('*',20)
  742. Say 'Testing error conditions...'
  743. Say Copies('*',20)
  744. Say 'errors: causing error in sqlconnect()... (may take a while to fail!)'
  745. If sqlconnect('c1','junk','junk','junk','junk') < 0 Then rc = Abort('connect:',1)
  746. Say 'errors: causing errors in sqlcommand()...'
  747. If sqlcommand('q1','select abc from junk') < 0 Then rc = Abort('command:',1)
  748. Call connect 'c1'
  749. If sqlcommand('q1','select abc from junk') < 0 Then rc = Abort('command:',1)
  750. Say 'errors: causing error in sqlexecute()...'
  751. If sqlexecute('q1') < 0 Then rc = Abort('execute:',1)
  752. Say 'errors: causing error in sqlopen()...'
  753. If sqlopen('q1') < 0 Then rc = Abort('open:',1)
  754. Say 'errors: causing error in sqlfetch()...'
  755. If sqlfetch('q1') < 0 Then rc = Abort('fetch:',1)
  756. If sqlprepare('q1','select * from RX_EMP') < 0 Then rc = Abort('prepare:')
  757. If sqlfetch('q1') < 0 Then rc = Abort('fetch:',1)
  758. If sqldispose('q1') < 0 Then rc = Abort('dispose:')
  759. Say 'errors: causing error with placemarkers...'
  760. If sqlvariable('USESPLACEMARKERS') = 0 Then
  761.    Say db 'does not support the use of placemarkers in queries. This test ignored.'
  762. Else
  763.   Do
  764.     rc = sqlvariable('STANDARDPLACEMARKERS',1)
  765.     If sqlprepare('q1','select * from RX_EMP where empid = ?') < 0 Then rc = Abort('prepare:')
  766.     If sqlopen('q1') < 0 Then rc = Abort('open:',1)
  767.     If sqlopen('q1','junk') < 0 Then rc = Abort('open:',1)
  768.     If sqlopen('q1','junk',10) < 0 Then rc = Abort('open:',1)
  769.     If sqldispose('q1') < 0 Then rc = Abort('dispose:')
  770.   End
  771. Call disconnect 'c1'
  772. Return
  773.  
  774. /*-----------------------------------------------------------------*/
  775. info: Procedure Expose sqlca. sqlconnect. db columnnames_emp columnnames_dept stringdatatypes_empid. stringdatatypes_deptno.
  776. Say Copies('*',20)
  777. Say 'Testing sqlvariable, sqlgetinfo and sqlsetinfo...'
  778. Say Copies('*',20)
  779. valid_info = 'SUPPORTSTRANSACTIONS SUPPORTSSQLGETDATA DBMSNAME',
  780.              'DBMSVERSION DESCRIBECOLUMNS DATATYPES'
  781. valid_variable = 'SUPPORTSDMLROWCOUNT SUPPORTSPLACEMARKERS',
  782.              'LONGLIMIT AUTOCOMMIT IGNORETRUNCATE NULLSTRINGIN NULLSTRINGOUT',
  783.              'STANDARDPLACEMARKERS DEBUG VERSION ROWLIMIT SAVESQL'
  784. Say 'info: Valid values for sqlvariable()...' valid_variable
  785. Do i = 1 to Words(valid_variable)
  786.    Say '      Current value for' Word(valid_variable,i) sqlvariable(Word(valid_variable,i))
  787. End
  788. Call connect 'c1'
  789. Say 'info: Valid values for sqlgetinfo()...' valid_info
  790. Do i = 1 to Words(valid_info)
  791.    rc = sqlgetinfo('c1',Word(valid_info,i),'desc.')
  792.    If rc < 0 Then Say '      ERROR:' sqlca.interrm ':' sqlca.sqlerrm
  793.    Else
  794.      Do
  795.        var = Word(valid_info,i)
  796.        Do j = 1 To desc.0
  797.          If j = 1 Then Say Left('      Current value for' var,40) desc.j
  798.          Else Say Copies(' ',40) desc.j
  799.        End
  800.      End
  801. End
  802. Call disconnect 'c1'
  803. Return
  804.  
  805. /*-----------------------------------------------------------------*/
  806. Abort: Procedure Expose sqlca.
  807. Parse Arg message, kontinue
  808. Say 'Error in' message
  809. If sqlca.intcode = -1 Then
  810.   Do
  811.     Say 'SQLCODE:' sqlca.sqlcode
  812.     Say 'SQLERRM:' sqlca.sqlerrm
  813.     Say 'SQLTEXT:' sqlca.sqltext
  814.   End
  815. Else
  816.   Do
  817.     Say 'INTCODE:' sqlca.intcode
  818.     Say 'INTERRM:' sqlca.interrm
  819.   End
  820. If kontinue = 1 Then Return 1
  821. Else Exit 1
  822.