home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rexxgdb2.zip / Run-G2.CMD < prev    next >
OS/2 REXX Batch file  |  1997-08-10  |  10KB  |  310 lines

  1. /* rexx */
  2. arg numrows .
  3. /*
  4. ------------------------------------------------------------------------
  5.                                  Run-G2
  6.                  DB2/2 Benchmark with REXX/Dynamic SQL
  7.     To insert 'numrows' rows to the STAFF table of the DB2/2 SAMPLE
  8.             Database & to read those back into REXX program
  9.  
  10.             Utilizing Global Automation Company's DB2/2 APIs
  11.                 combined with IBM's DB2/2 API (SQLEXEC)
  12.  
  13.                 Copyright (C) 1995 Global Automation Co.
  14.                           All Rights Reserved
  15.  
  16.                          Written By Simon Husin
  17.                          June - December, 1995
  18. ------------------------------------------------------------------------
  19.  
  20.          To use from an OS/2 Full Screen Command Prompt Screen:
  21.                  Type Run-G2 'numrows' and press Enter
  22.         where 'numrows' is number of rows to insert w/ ID > 1000
  23.        if not entered or invalid (<1 or > 9999), it is set to 100
  24. ------------------------------------------------------------------------
  25. */
  26. '@echo off'
  27. line = copies('-', 79)
  28. call ShowTitle
  29.  
  30. /*
  31. Validate 'numrows'
  32. */
  33. if numrows = '' then numrows = 100
  34. if datatype(numrows) \= 'NUM' then numrows = 100
  35. if numrows < 1 | numrows > 9999 then numrows = 100
  36. numrows = numrows % 1
  37.  
  38. /*
  39. Initialize all SQL statements to be used later in the program
  40. */
  41. /*
  42. Initialize all SQL statements to be prepared later in the program
  43. Also the SQLEXEC to execute those statements
  44. */
  45. /* SQL Select data from table Staff */
  46. sqlquery = 'SELECT ID,NAME,DEPT,JOB,YEARS,SALARY,COMM' ||,
  47.            '  FROM STAFF'                              ||,
  48.            ' WHERE ID > 0'
  49.  
  50. /* SQL Fetch C1 */
  51. sqlfetch = 'FETCH C1' ||,
  52.            ' INTO :ID,:NAME,:DEPT,:JOB,:YEARS:YEARSI,:SALARY,'||,
  53.            '      :COMM:COMMI'
  54.  
  55. /* SQL Insert w/ placeholders */
  56. sqlinsert = ' INSERT' ||,
  57.             '   INTO STAFF(ID,NAME,DEPT,JOB,YEARS,SALARY,COMM)'||,
  58.             '       VALUES( ?,   ?,   ?,  ?,    ?,     ?,   ?)'
  59.  
  60. /* SQL Execute S2 */
  61. sqlexins =  'EXECUTE S2 USING' ||,
  62.             '    :COUNT,:NAME,:DEPT,:JOB,:YEARS:YEARSI,:SALARY,'||,
  63.             '    :COMM:COMMI'
  64.  
  65. /* SQL Select all newly inserted data */
  66. G2querynew = 'SELECT ID,NAME,DEPT,JOB,YEARS,SALARY,COMM' ||,
  67.              ' FROM STAFF'                               ||,
  68.              '  WHERE ID > 1000'
  69.  
  70. /* 2 SQL Select COUNTs in a UNION */
  71. G2count = 'SELECT COUNT(*)'        ||,
  72.           '  FROM STAFF'       ||,
  73.           ' UNION '            ||,
  74.           'SELECT COUNT(*)'    ||,
  75.           '  FROM STAFF'       ||,
  76.           ' WHERE ID > 1000'
  77.  
  78. /* SQL Delete created rows */
  79. sqldelete = 'DELETE FROM STAFF WHERE ID > 1000'
  80.  
  81. /*
  82. Attach REXX functions in SQLDBS to start the Database 2 for OS/2 (DB2/2)
  83. */
  84. if rxfuncquery('SQLDBS') \= 0 then do
  85.    say 'Attaching REXX DB2/2 Database Manager APIs...'
  86.    call rxfuncadd 'SQLDBS', 'SQLAR', 'SQLDBS'
  87.    end
  88. if rxfuncquery('SQLEXEC') \= 0 then do
  89.    say 'Attaching REXX DB2/2 SQL APIs...'
  90.    call rxfuncadd 'SQLEXEC', 'DB2AR', 'SQLEXEC'
  91.    end
  92. if rxfuncquery('G2LoadFuncs') \= 0 then do
  93.    say 'Attaching REXXGDB2 APIs...'
  94.    call rxfuncadd 'G2LoadFuncs', 'REXXGDB2', 'G2LoadFuncs'
  95.    call G2LoadFuncs
  96.    end
  97.  
  98. /* Activate DB2/2 via API*/
  99. say 'Starting Database Manager...'
  100. call SQLDBS 'START DATABASE MANAGER'
  101. if sqlca.sqlcode \= 0 &,
  102.    sqlca.sqlcode \= -1026 &,           /* DB2/2 is already active     */
  103.    sqlca.sqlcode \= -1063 then         /* STARTDBM was successful     */
  104.    call sqlerror 100
  105. /*
  106. ------------------------------------------------------------------------
  107. */
  108. call G2connectreset                    /* disconnecting prev. connect.*/
  109. /*
  110. ------------------------------------------------------------------------
  111. */
  112. /* Open the database */
  113. say 'Connecting to Sample Database...'
  114. call time 'R'
  115. call G2connectshare 'SAMPLE'
  116. elapse.connect = time('E')
  117.  
  118. /* Change Current Query Optimization to 0 */
  119. /*
  120. say 'Set Current Query Optimization to 0...'
  121. call time 'R'
  122. sql = 'SET CURRENT QUERY OPTIMIZATION 0'
  123. call SQLEXEC 'EXECUTE IMMEDIATE :sql'
  124. elapse.queryopt= time('E')
  125. */
  126.  
  127. /* Change Current Query Optimization to 0 */
  128. say 'Set Current Query Optimization to 0...'
  129. call time 'R'
  130. call G2SetCurQueryOpt 0
  131. elapse.queryopt= time('E')
  132.  
  133. select
  134.         /*unit of work not done*/
  135.    when result = -752 then call sqlerror -752
  136.         /*database not found*/
  137.    when result = -1013 then call sqlerror -1013
  138.         /*db dir. not found*/
  139.    when result = -1031 then call sqlerror -1031
  140.    when result = -1026 then nop            /* DB2/2 is already active */
  141.    when result \= 0 then
  142.         say 'RESULT='result
  143.    otherwise nop
  144.    end
  145. /*
  146. ------------------------------------------------------------------------
  147. */
  148. /* Prepare the query */
  149. CALL SQLEXEC 'PREPARE S1 FROM :SQLQUERY'
  150.  
  151. /* Declare cursor */
  152. CALL SQLEXEC 'DECLARE C1 CURSOR FOR S1'
  153.  
  154. /* Open cursor */
  155. CALL SQLEXEC 'OPEN C1'
  156.  
  157. /* Fetch one row from the STAFF table */
  158. CALL SQLEXEC sqlfetch
  159. if sqlca.sqlcode \= 0 then
  160.    call sqlerror 101
  161.  
  162. /* Make corrections based on the NULL indicators */
  163. if yearsi = -1 then years = 0
  164. if commi = -1  then comm  = 0
  165.  
  166. /* Display the first (fetched) STAFF rows */
  167. say 'ID.......' id
  168. say 'NAME.....' name
  169. say 'DEPT.....' dept
  170. say 'JOB......' job
  171. say 'YEARS....' left(format(years, 2), 20) ||,
  172.                 '(NULL indicator='yearsi')'
  173. say 'SALARY...' format(salary, 6, 2)
  174. say 'COMM.....' left(format(comm, 6, 2), 20) ||,
  175.                 '(NULL indicator='commi')'
  176.  
  177. /* Close the cursor */
  178. CALL SQLEXEC 'CLOSE C1'
  179. elapse.insert = time('E')
  180. /*
  181. ------------------------------------------------------------------------
  182. */
  183. /* Inserting 'NUMROWS' rows with a commit for every 100 inserts */
  184. maxid = numrows + 1000
  185.  
  186. say 'Inserting first Staff row' numrows' times w/ a commit @100 rows...'
  187. call Time 'R'
  188.  
  189. CALL SQLEXEC 'PREPARE S2 FROM :SQLINSERT'
  190.  
  191. /* Do 'numrows' inserts w/ commits every 100 times */
  192. do count = 1001 to maxid while sqlca.sqlcode = 0
  193.    CALL SQLEXEC sqlexins
  194.    if right(count, 2) \= '00' then iterate
  195.  
  196.    if count = maxid then leave
  197.  
  198.    CALL SQLEXEC 'COMMIT'
  199.    CALL SQLEXEC 'PREPARE S2 FROM :SQLINSERT'
  200.    end
  201.  
  202. if sqlca.sqlcode \= 0 then
  203.    call sqlerror 201
  204.  
  205. CALL SQLEXEC 'COMMIT'
  206. elapse.insert = time('E')
  207. /*
  208. ------------------------------------------------------------------------
  209. */
  210. /* Reading the 'NUMROWS' rows just inserted */
  211. say 'Reading all rows with ID > 1000 (into memory only)...'
  212. call Time 'R'
  213.  
  214. call G2selectform G2querynew, 'form.', 9999999
  215. elapse.readnew = time('E')
  216.  
  217. say 'Number of rows read..:' form.0
  218.  
  219. drop form.
  220. /*
  221. ------------------------------------------------------------------------
  222. */
  223. /* Reading rows from staff table using DB2/2 COUNT(*) and UNION */
  224. say 'Obtaining #rows w/ ID > 0 & 1000 w/ SQL COUNT & UNION...'
  225. call Time 'R'
  226.  
  227. call G2selectdata G2count, 'data.', 9999
  228.  
  229. do i = 1 to data.0
  230.    say '- Found' data.i.1 'rows...'
  231.    end
  232. elapse.count = time('E')
  233. /*
  234. ------------------------------------------------------------------------
  235. */
  236. /* Deleting all (new) rows */
  237. say 'Deleting all rows with ID > 1000...'
  238. call Time 'R'
  239. call G2immediate SQLDELETE
  240. elapse.delete = time('E')
  241. /*
  242. ------------------------------------------------------------------------
  243. */
  244. /* Committing the unit of works */
  245. say 'Committing the unit of works...'
  246. call Time 'R'
  247. call G2commit
  248. elapse.commit = time('E')
  249. /*
  250. ------------------------------------------------------------------------
  251. */
  252. /* Close the database */
  253. say 'Disconnecting from Sample Database...'
  254. call time 'R'
  255. call G2connectreset
  256. elapse.disconnect = time('E')
  257. /*
  258. ------------------------------------------------------------------------
  259. */
  260. call ShowTitle
  261. tottime = 0
  262. tottime = tottime + elapse.connect
  263. tottime = tottime + elapse.queryopt
  264. tottime = tottime + elapse.insert
  265. tottime = tottime + elapse.readnew
  266. tottime = tottime + elapse.count
  267. tottime = tottime + elapse.delete
  268. tottime = tottime + elapse.commit
  269. tottime = tottime + elapse.disconnect
  270.  
  271. tottimefactor = tottime / 100
  272.  
  273. say line
  274. say left('Results', 20) right('Seconds', 12) right('Total %', 12)
  275. say line
  276. say left('Connect', 20) format(elapse.connect, 9, 2) format(elapse.connect / tottimefactor, 9, 2)
  277. say left('Query Opt.', 20) format(elapse.queryopt, 9, 2) format(elapse.queryopt / tottimefactor, 9, 2)
  278. say left('Insert', 20) format(elapse.insert, 9, 2) format(elapse.insert / tottimefactor, 9, 2)
  279. say left('Read New', 20) format(elapse.readnew, 9, 2) format(elapse.readnew / tottimefactor, 9, 2)
  280. say left('Count', 20) format(elapse.count, 9, 2) format(elapse.count / tottimefactor, 9, 2)
  281. say left('Delete', 20) format(elapse.delete, 9, 2) format(elapse.delete / tottimefactor, 9, 2)
  282. say left('Commit', 20) format(elapse.commit, 9, 2) format(elapse.commit / tottimefactor, 9, 2)
  283. say left('Disconnect', 20) format(elapse.disconnect, 9, 2) format(elapse.disconnect / tottimefactor, 9, 2)
  284. say line
  285. say left('Total', 20) format(tottime, 9, 2) format(tottime / tottimefactor, 9, 2)
  286. say line
  287. return 0
  288.  
  289.  
  290. ShowTitle:
  291. 'cls'
  292. say
  293. say 'Run-G2 --- Benchmarking REXX - DB2/2 Interface'
  294. say '           Using IBM & GAC DB2/2 REXX APIs'
  295. say 'Copyright (C) 1995 Global Automation Co.'
  296. say 'All Rights Reserved'
  297. say
  298. return
  299.  
  300.  
  301. sqlerror:
  302. arg errorcode
  303. say
  304. say 'SQL/DBS Related errors detected.'
  305. say 'ERRORCODE  =' errorcode
  306. say 'RESULT     =' result
  307. say 'Program terminated!'
  308.  
  309. exit 0
  310.