home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / oraperl2.zip / mkdb.pl < prev    next >
Perl Script  |  1993-07-01  |  2KB  |  96 lines

  1. #!./oraperl
  2. #
  3. # mkdb.pl
  4. #
  5. # Sample oraperl program to create a new database and load data into it.
  6. #
  7. # Author:    Kevin Stock
  8. # Date:        5th August 1991
  9. #
  10.  
  11. # make sure that we really are running oraperl
  12. die ("You should use oraperl, not perl\n") unless defined &ora_login;
  13.  
  14. # get debugging & error codes
  15. require('oraperl.ph');
  16.  
  17. # let's see what oraperl is doing when it executes this
  18. $ora_debug = $ODBG_EXEC | $ODBG_STRNUM | $ODBG_MALLOC;
  19.  
  20. # set these as strings to make the code more readable
  21. $CREATE = "create table tryit (name char(10), ext number(3))";
  22. $INSERT = "insert into tryit values (:1, :2)";
  23. $LIST    = "select * from tryit order by name";
  24. $DELETE    = "delete from tryit where name = :1";
  25. $DROP    = "drop table tryit";
  26.  
  27. format top =
  28.        Name         Ext
  29.        ====         ===
  30. .
  31.  
  32. format STDOUT =
  33.        @<<<<<<<<<   @>>
  34.        $name,       $ext
  35. .
  36.  
  37. # function to list the database
  38.  
  39. sub list
  40. {
  41.     local($csr, $name, $ext);
  42.  
  43.     $- = 0;
  44.  
  45.     $csr = &ora_open($lda, $LIST)            || die $ora_errstr;
  46.     while (($name, $ext) = &ora_fetch($csr))
  47.     {
  48.         write;
  49.     }
  50.     die $ora_errstr if ($ora_errno != 0);
  51.     do ora_close($csr)                || die $ora_errstr;
  52. }
  53.  
  54. # create the database
  55.  
  56. $lda = &ora_login("t", "kstock", "kstock")    || die $ora_errstr;
  57. &ora_do($lda, $CREATE)                || die $ora_errstr;
  58.  
  59. # put some data into it
  60.  
  61. $csr = &ora_open($lda, $INSERT)            || die $ora_errstr;
  62. while (<DATA>)
  63. {
  64.     m/([a-z]+):([0-9]+)/;
  65.     do ora_bind($csr, $1, $2);
  66. }
  67. do ora_close($csr)                || die $ora_errstr;
  68.  
  69. # check the result
  70. do list();
  71.  
  72. # remove a few lines
  73.  
  74. $csr = &ora_open($lda, $DELETE)            || die $ora_errstr;
  75. foreach $name ('catherine', 'angela', 'arnold', 'julia')
  76. {
  77.     &ora_bind($csr, $name)            || die $ora_errstr;
  78. }
  79. &ora_close($csr)                || die $ora_errstr;
  80.  
  81. # check the result
  82. do list();
  83.  
  84. # remove the database and log out
  85. $csr = &ora_do($lda, $DROP)            || die $ora_errstr;
  86. do ora_logoff($lda)                || die $ora_errstr;
  87.  
  88. # This is the data which will go into the database
  89. __END__
  90. julia:292
  91. angela:208
  92. larry:424
  93. catherine:201
  94. randall:306
  95. arnold:305
  96.