home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / genmb108.zip / dbtest2.nrx < prev    next >
Text File  |  1996-11-07  |  4KB  |  121 lines

  1. /* 
  2.     A simple netrexx program to test RXDbase.
  3.     This time we will read infos directly from the .def
  4.     file.
  5.  
  6.     PLEASE: run this example _after_ running dbtest!
  7. */
  8.  
  9. options binary
  10.  
  11. import RXDbase
  12.  
  13. /* Here the variables declaration */
  14.  
  15. dbMine = RXDbase() /* instance which will handle the db */
  16.  
  17. rRec = Rexx[,]      /* Here we will store DB infos */
  18. rRec2 = Rexx[2]     /* Used to handle (un)delete - we will delete only 1 item */
  19. rArr = Rexx[3,3]   /* Used to store data to be written in the archive */
  20. rArr2 = Rexx[,]    /* Used to retrieve data from the archive (could have done
  21.                       it with rArr as well, but did this way for clarity) */
  22.  
  23. rFileName = Rexx null /* The DB name */
  24.  
  25. iCount = int 0        /* counters used in the program */
  26. iCount2 = int 0
  27.  
  28.  
  29. /* Here the body of the example */
  30.  
  31. /* First of all, let's connect to the database */
  32.  
  33. rFileName = 'db'   /* Name of the db - I got imagination, heh? */
  34.  
  35. say 'After the connection the DB is: 'dbMine.connect(rFileName)
  36. rRec = dbMine.getdbinfo() /* We just got the DB record structure */
  37.  
  38. /* Now, let's write a couple of records */
  39.  
  40. rArr[0,0] = 2              /* Number of records to be saved on disk */
  41. rArr[1,1] = 'Max'          /* First field of the first record. */
  42. rArr[2,1] = 'Marsiglietti' /* Second field of the first record. */
  43. rArr[1,2] = 'Mike'         /* First field of the second record. */
  44. rArr[2,2] = 'Cowlishaw'    /* Second field of the second record. */
  45.  
  46. say 'The write operation reported: 'dbMine.saverec(rArr, "OVERWRITE")
  47.  
  48. /* Retrieve those records and display them on screen */
  49.  
  50. rArr2 = dbMine.loadrec("Name", "all", "1", 1)
  51. /*
  52.    The former line uses "name" as the index.
  53.    Also, "1" means 1st record in the specified index.
  54. */
  55.  
  56. say rArr2[0,0] || ' records were loaded.'
  57.  
  58. loop iCount = 1 to rArr2[0,0]
  59.  if rArr2[3, iCount] \='N' then  /* If it's 'N' then it's deleted */
  60.  loop iCount2 = 1 to rRec[0,0]
  61.   say 'Record ' iCount', field 'rRec[iCount2,1]': 'rArr2[iCount2, iCount]
  62.  end
  63. end
  64.  
  65. say 'Now deleting Mike!! (haha)'
  66.  
  67. rRec2[0]=1 /* How many rec to delete/undelete? */
  68. rRec2[1]=2 /* Which one to delete/undelete? */
  69. say dbMine.delerec(rRec2, 1) /* 1 = Delete it */
  70.  
  71. /* Retrieve those records and display them on screen */
  72.  
  73. rArr2 = dbMine.loadrec("Name", "all", "1", 1)
  74. /*
  75.    The former line uses "name" as the index.
  76.    Also, "1" means 1st record in the specified index.
  77. */
  78.  
  79. say rArr2[0,0] || ' records were loaded.'
  80.  
  81. loop iCount = 1 to rArr2[0,0]
  82.  if rArr2[3, iCount] \='N' then
  83.  loop iCount2 = 1 to rRec[0,0]
  84.   say 'Record ' iCount', field 'rRec[iCount2,1]': 'rArr2[iCount2, iCount]
  85.  end
  86. end
  87.  
  88. say 'Now un-deleting Mike, and changing Max to Massimiliano:'
  89.  
  90. rRec2[0]=1 /* How many rec to delete/undelete? */
  91. rRec2[1]=2 /* Which one to delete/undelete? */
  92. say dbMine.delerec(rRec2, 0) /* 0 = Undelete it */
  93.  
  94. rArr[0,0] = 1              /* Number of records to be modified */
  95. rArr[0,1] = 1              /* Where has this record to be put? */
  96. rArr[1,1] = 'Massimiliano' /* First field of the first record. */
  97. rArr[2,1] = 'Marsiglietti' /* Second field of the first record. */
  98. say dbMine.modirec(rArr)
  99.  
  100. /* Retrieve those records and display them on screen */
  101.  
  102. rArr2 = dbMine.loadrec("Name", "all", "1", 1)
  103. /*
  104.    The former line uses "name" as the index.
  105.    Also, "1" means 1st record in the specified index.
  106. */
  107.  
  108. say rArr2[0,0] || ' records were loaded.'
  109.  
  110. loop iCount = 1 to rArr2[0,0]
  111.  if rArr2[3, iCount] \='N' then
  112.  loop iCount2 = 1 to rRec[0,0]
  113.   say 'Record ' iCount', field 'rRec[iCount2,1]': 'rArr2[iCount2, iCount]
  114.  end
  115. end
  116.  
  117. /* We just got enough */
  118.  
  119. say 'Disconnection returned: 'dbMine.disconnect()
  120.  
  121.