home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 1997 September / Personal_Computer_World_Sep_97.iso / DXRS / SLIPCW09.DXR / 00017_databasehandlers.ls < prev    next >
Encoding:
Text File  |  1997-06-27  |  5.5 KB  |  192 lines

  1. on dbfind me, afield, operator, criteria
  2.   global database, table, dbinstance, tableinstance, totnumrecs, listfields
  3.   if objectp(tableinstance) = 1 then
  4.     mSetIndex(tableinstance, "primeidx")
  5.     mSelect(tableinstance)
  6.     mSetCriteria(tableinstance, afield, operator, criteria)
  7.     mSelect(tableinstance)
  8.     set howmanyselected to mSelectCount(tableinstance)
  9.     mGoFirst(tableinstance)
  10.     set foundlist to list()
  11.     repeat with i = 1 to howmanyselected
  12.       append(foundlist, mGetField(tableinstance, afield))
  13.       if i < (mSelectCount(tableinstance) + 1) then
  14.         mGoNext(tableinstance)
  15.         next repeat
  16.       end if
  17.       exit repeat
  18.     end repeat
  19.   else
  20.     put "no tableinstance object found"
  21.   end if
  22.   mSetIndex(tableinstance, "primeidx")
  23.   mSelect(tableinstance)
  24.   return foundlist
  25. end
  26.  
  27. on dbclosesession me
  28.   global database, table, dbinstance, tableinstance, totnumrecs, listfields
  29.   if objectp(table) = 1 then
  30.     put "object table exists"
  31.     set table to EMPTY
  32.     put "table object instance now  = " & objectp(table)
  33.   else
  34.     put "no object found"
  35.   end if
  36.   if objectp(database) = 1 then
  37.     put "object table exists"
  38.     set database to EMPTY
  39.     put "database object instance now  = " & objectp(database)
  40.   else
  41.     put "no object found"
  42.   end if
  43.   if objectp(tableinstance) = 1 then
  44.     put "object tableinstance exists"
  45.     set tableinstance to EMPTY
  46.     put "tableinstance object instance now  = " & objectp(tableinstance)
  47.   else
  48.     put "no object found"
  49.   end if
  50.   if objectp(dbinstance) = 1 then
  51.     put "object table exists"
  52.     set dbinstance to EMPTY
  53.     put "dbinstance object instance now  = " & objectp(dbinstance)
  54.   else
  55.     put "no object found"
  56.   end if
  57.   updateStage()
  58. end
  59.  
  60. on dbgo me, whichrecord
  61.   global database, table, dbinstance, tableinstance, totnumrecs, listfields
  62.   if objectp(tableinstance) = 1 then
  63.     mSetIndex(tableinstance, "primeidx")
  64.     mSelect(tableinstance)
  65.     if value(whichrecord) <= totnumrecs then
  66.       mGo(tableinstance, whichrecord)
  67.     else
  68.       put "maximum record encountered at " & totnumrecs
  69.       mGo(tableinstance, totnumrecs)
  70.     end if
  71.   else
  72.     put "no tableinstance object found"
  73.   end if
  74. end
  75.  
  76. on dbcount me
  77.   global database, table, dbinstance, tableinstance
  78.   set totnumrecs to 0
  79.   if objectp(tableinstance) = 1 then
  80.     mSetIndex(tableinstance, "primeidx")
  81.     mSelect(tableinstance)
  82.     set totnumrecs to mSelectCount(tableinstance)
  83.   else
  84.     put "no tableinstance object found"
  85.   end if
  86.   return totnumrecs
  87. end
  88.  
  89. on dblistfields me, table
  90.   global database, table, dbinstance, tableinstance
  91.   set listfields to list()
  92.   if objectp(dbinstance) = 1 then
  93.     set layout to mDumpStructure(dbinstance)
  94.     set lineCount to the number of lines in layout
  95.     repeat with i = 1 to lineCount
  96.       if line i of layout contains "-field" then
  97.         set thisfieldname to EMPTY
  98.         repeat with j = 1 to the number of chars in line i of layout
  99.           if charToNum(char j of line i of layout) = 39 then
  100.             set characternumber to j
  101.             exit repeat
  102.           end if
  103.         end repeat
  104.         repeat with k = characternumber + 1 to the number of chars in line i of layout
  105.           if charToNum(char k of line i of layout) <> 39 then
  106.             set thisfieldname to thisfieldname & char k of line i of layout
  107.             next repeat
  108.           end if
  109.           exit repeat
  110.         end repeat
  111.         append(listfields, thisfieldname)
  112.       end if
  113.     end repeat
  114.   else
  115.     put "dbinstance object does not exist"
  116.   end if
  117.   return listfields
  118. end
  119.  
  120. on dbnext me
  121.   global database, table, dbinstance, tableinstance, totnumrecs, listfields
  122.   if objectp(tableinstance) = 1 then
  123.     mGoNext(tableinstance)
  124.   else
  125.     put "tableinstance object does not exist"
  126.   end if
  127. end
  128.  
  129. on dbgetfield me, fieldName
  130.   global database, table, dbinstance, tableinstance, totnumrecs, listfields
  131.   set fieldcontent to EMPTY
  132.   repeat with i = 1 to count(listfields)
  133.     if getAt(listfields, i) = fieldName then
  134.       if objectp(tableinstance) = 1 then
  135.         set fieldcontent to mGetField(tableinstance, fieldName)
  136.         next repeat
  137.       end if
  138.       put "tableinstance object does not exist"
  139.     end if
  140.   end repeat
  141.   return fieldcontent
  142. end
  143.  
  144. on dbopensession me
  145.   global database, table, dbinstance, tableinstance, totnumrecs, listfields
  146.   if (objectp(database) <> 1) and (objectp(table) <> 1) then
  147.     set database to xtra("v12dbe")
  148.     put database
  149.     set table to xtra("v12table")
  150.     put table
  151.   else
  152.     put "objects already exist" & database & table
  153.     return 0
  154.   end if
  155.   updateStage()
  156. end
  157.  
  158. on dbuse me, dbName, thepassword, tableName
  159.   global database, table, dbinstance, tableinstance, totnumrecs, listfields
  160.   if (objectp(database) = 1) and (objectp(dbinstance) <> 1) then
  161.     set dbinstance to new(database, the pathName & dbName, "readonly", thepassword)
  162.     put dbinstance
  163.   end if
  164.   if (objectp(table) = 1) and (objectp(tableinstance) <> 1) then
  165.     set tableinstance to new(table, mGetRef(dbinstance), tableName)
  166.     put tableinstance
  167.   end if
  168.   if objectp(dbinstance) = 1 then
  169.     set totnumrecs to dbcount(me)
  170.     set listfields to dblistfields(me, dbName)
  171.   end if
  172. end
  173.  
  174. on dbprevious me
  175.   global database, table, dbinstance, tableinstance, totnumrecs, listfields
  176.   if objectp(tableinstance) = 1 then
  177.     mGoPrevious(tableinstance)
  178.   else
  179.     put "tableinstance object does not exist"
  180.   end if
  181. end
  182.  
  183. on dbselectall me
  184.   global database, table, dbinstance, tableinstance, totnumrecs, listfields
  185.   if objectp(tableinstance) = 1 then
  186.     mSetIndex(tableinstance, "primeidx")
  187.     mSelect(tableinstance)
  188.   else
  189.     put "tableinstance object does not exist"
  190.   end if
  191. end
  192.