Guest User

Untitled

a guest
Jul 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. public void tableUDF(double inSalaryFactor,
  2. String outName,
  3. String outJob,
  4. double outNewSalary)
  5. throws Exception
  6. {
  7. int intRow = 0;
  8. byte[] scratchpad = getScratchpad();
  9.  
  10. // variables to read from SCRATCHPAD area
  11. ByteArrayInputStream
  12. byteArrayIn = new ByteArrayInputStream(scratchpad);
  13. DataInputStream
  14. dataIn = new DataInputStream(byteArrayIn);
  15.  
  16. // variables to write into SCRATCHPAD area
  17. byte[] byteArrayRow;
  18. int i;
  19. ByteArrayOutputStream
  20. byteArrayOut = new ByteArrayOutputStream(10);
  21. DataOutputStream
  22. dataOut = new DataOutputStream(byteArrayOut);
  23.  
  24. switch (getCallType())
  25. {
  26. case SQLUDF_TF_FIRST:
  27. // do initialization for the whole statement
  28. // (the statement may invoke tableUDF more than once)
  29. break;
  30. case SQLUDF_TF_OPEN:
  31. // do initialization valid for this invokation of tableUDF
  32.  
  33. intRow = 1;
  34. // save data in SCRATCHPAD area
  35. dataOut.writeInt(intRow);
  36. byteArrayRow = byteArrayOut.toByteArray();
  37. for(i = 0; i < byteArrayRow.length; i++)
  38. {
  39. scratchpad[i] = byteArrayRow[i];
  40. }
  41. setScratchpad(scratchpad);
  42. break;
  43. case SQLUDF_TF_FETCH:
  44. // get data from SCRATCHPAD area
  45. intRow = dataIn.readInt();
  46. // work with data
  47. if(intRow > staff.length)
  48. {
  49. // Set end-of-file signal and return
  50. setSQLstate ("02000");
  51. }
  52. else
  53. {
  54. // Set the current output row and increment the row number
  55. set(2, staff[intRow - 1].getName());
  56. set(3, staff[intRow - 1].getJob());
  57. set(4, staff[intRow - 1].getSalary() * inSalaryFactor);
  58. intRow++;
  59. }
  60.  
  61. // save data in SCRATCHPAD area
  62. dataOut.writeInt(intRow);
  63. byteArrayRow = byteArrayOut.toByteArray();
  64. for(i = 0; i < byteArrayRow.length; i++)
  65. {
  66. scratchpad[i] = byteArrayRow[i];
  67. }
  68. setScratchpad(scratchpad);
  69. break;
  70. case SQLUDF_TF_CLOSE:
  71. break;
  72. case SQLUDF_TF_FINAL:
  73. break;
  74. }
  75. } // tableUDF
Add Comment
Please, Sign In to add comment