home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Product / Product.zip / viper092.zip / CREATEDB.CMD < prev    next >
OS/2 REXX Batch file  |  1995-09-20  |  5KB  |  142 lines

  1. /*      VIPER Database Engine
  2.         Create a database and database index example.
  3.         Copyright (c) - 1995 by Douglas A. Bebber
  4. */
  5.  
  6.  
  7. /* Register the VIPER Database Engine functions... */
  8. rc = RxFuncAdd("SysLoadViperFuncs","Viper", "SysLoadViperFuncs")
  9. call SysLoadViperFuncs
  10.  
  11. /* The CUSTOMER database used in these examples is created here. The CUSTOMER
  12.     database field definition is detailed below:
  13.  
  14.         ID
  15.         Last Name
  16.         First Name
  17.         MI
  18.         Address
  19.         City
  20.         State
  21.         ZIP
  22.         Phone
  23.  
  24.         Now we will create this database:
  25. */
  26.  
  27. DatabaseFields.0 = 9    /* 9 fields in the CUSTOMER database */
  28. DatabaseFields.1 = 'ID'
  29. DatabaseFields.2 = 'Last Name'
  30. DatabaseFields.3 = 'First Name'
  31. DatabaseFields.4 = 'MI'
  32. DatabaseFields.5 = 'Address'
  33. DatabaseFields.6 = 'City'
  34. DatabaseFields.7 = 'State'
  35. DatabaseFields.8 = 'Zip'
  36. DatabaseFields.9 = 'Phone'
  37.  
  38. rc = RxViperCreateDatabase('CUSTOMER', '0', DatabaseFields.)
  39. if rc = 0 then
  40.         say 'Error creating the CUSTOMER database!'
  41. else
  42.         say 'Successfully created the CUSTOMER database!'
  43.  
  44. /****************************************************************************/
  45. /* Now create an index to order customer names alphabetically by Last Name, then First Name */
  46. /*****************************************************************************/
  47.  
  48.  
  49. KeyFields.0 = 2
  50. KeyFields.1 = 'Last Name'
  51. KeyFields.2 = 'First Name'
  52.  
  53. rc = RxViperCreateIndex('CUSTOMER', 'LNAME', KeyFields.)
  54. if rc = 0 then
  55.         say 'Error creating the CUSTOMER database LNAME index!'
  56. else
  57.         say 'Successfully created the CUSTOMER database LNAME index!'
  58.  
  59.  
  60. /****************************************************************************/
  61. /* Now create an index to order customer names by State then alphabetically by Last Name,   */
  62. /* then First Name                                                                                 */
  63. /****************************************************************************/
  64.  
  65.  
  66. KeyFields.0 = 3
  67. KeyFields.1 = 'State'
  68. KeyFields.2 = 'Last Name'
  69. KeyFields.3 = 'First Name'
  70.  
  71. rc = RxViperCreateIndex('CUSTOMER', 'STATE', KeyFields.)
  72. if rc = 0 then
  73.         say 'Error creating the CUSTOMER database STATE index!'
  74. else
  75.         say 'Successfully created the CUSTOMER database STATE index!'
  76.  
  77. /****************************************************************************/
  78. /* Now lets just add a few records into the database:                                            */
  79. /****************************************************************************/
  80. Record.0 = 9
  81. Record.1 = '123-45-6789'
  82. Record.2 = 'Doe'
  83. Record.3 = 'John'
  84. Record.4 = 'D'
  85. Record.5 = '1212 West Lake Drive'
  86. Record.6 = 'Cedar Rapids'
  87. Record.7 = 'IA'
  88. Record.8 = '52804'
  89. Record.9 = '(319) 322-8876'
  90. rc = RxViperAddRecord('CUSTOMER','LNAME', Record.) /* Specify any index, all indexes are updated */
  91. if rc = 0 then
  92.         say 'Error adding record to the CUSTOMER database!'
  93. else
  94.         say 'Successfully added record to the CUSTOMER database!'
  95.  
  96. Record.0 = 9
  97. Record.1 = '123-45-6790'
  98. Record.2 = 'Doe'
  99. Record.3 = 'Jane'
  100. Record.4 = 'T'
  101. Record.5 = '1212 West Lake Drive'
  102. Record.6 = 'Cedar Rapids'
  103. Record.7 = 'IA'
  104. Record.8 = '52804'
  105. Record.9 = '(319) 322-8876'
  106. rc = RxViperAddRecord('CUSTOMER','LNAME', Record.) /* Specify any index, all indexes are updated */
  107. if rc = 0 then
  108.         say 'Error adding record to the CUSTOMER database!'
  109. else
  110.         say 'Successfully added record to the CUSTOMER database!'
  111.  
  112.  
  113. Record.0 = 9
  114. Record.1 = '323-19-0020'
  115. Record.2 = 'Smith'
  116. Record.3 = 'Bob'
  117. Record.4 = 'G'
  118. Record.5 = '1004 South Williamson Parkway - Building #43, Suite #2987'
  119. Record.6 = 'Sarasota'
  120. Record.7 = 'FL'
  121. Record.8 = '34231'
  122. Record.9 = '(941) 322-4576'
  123. rc = RxViperAddRecord('CUSTOMER','LNAME', Record.) /* Specify any index, all indexes are updated */
  124. if rc = 0 then
  125.         say 'Error adding record to the CUSTOMER database!'
  126. else
  127.         say 'Successfully added record to the CUSTOMER database!'
  128.  
  129.  
  130. /****************************************************************************/
  131. /* Now close the database file:                                                                    */
  132. /****************************************************************************/
  133.  
  134. rc = RxViperCloseDatabase('CUSTOMER')
  135. if rc = 0 then
  136.         say 'Error closing the new CUSTOMER database!'
  137. else
  138.         say 'Successfully closed the new CUSTOMER database!'
  139.  
  140.  
  141. call SysDropFuncs
  142.