Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void tableUDF(double inSalaryFactor,
- String outName,
- String outJob,
- double outNewSalary)
- throws Exception
- {
- int intRow = 0;
- byte[] scratchpad = getScratchpad();
- // variables to read from SCRATCHPAD area
- ByteArrayInputStream
- byteArrayIn = new ByteArrayInputStream(scratchpad);
- DataInputStream
- dataIn = new DataInputStream(byteArrayIn);
- // variables to write into SCRATCHPAD area
- byte[] byteArrayRow;
- int i;
- ByteArrayOutputStream
- byteArrayOut = new ByteArrayOutputStream(10);
- DataOutputStream
- dataOut = new DataOutputStream(byteArrayOut);
- switch (getCallType())
- {
- case SQLUDF_TF_FIRST:
- // do initialization for the whole statement
- // (the statement may invoke tableUDF more than once)
- break;
- case SQLUDF_TF_OPEN:
- // do initialization valid for this invokation of tableUDF
- intRow = 1;
- // save data in SCRATCHPAD area
- dataOut.writeInt(intRow);
- byteArrayRow = byteArrayOut.toByteArray();
- for(i = 0; i < byteArrayRow.length; i++)
- {
- scratchpad[i] = byteArrayRow[i];
- }
- setScratchpad(scratchpad);
- break;
- case SQLUDF_TF_FETCH:
- // get data from SCRATCHPAD area
- intRow = dataIn.readInt();
- // work with data
- if(intRow > staff.length)
- {
- // Set end-of-file signal and return
- setSQLstate ("02000");
- }
- else
- {
- // Set the current output row and increment the row number
- set(2, staff[intRow - 1].getName());
- set(3, staff[intRow - 1].getJob());
- set(4, staff[intRow - 1].getSalary() * inSalaryFactor);
- intRow++;
- }
- // save data in SCRATCHPAD area
- dataOut.writeInt(intRow);
- byteArrayRow = byteArrayOut.toByteArray();
- for(i = 0; i < byteArrayRow.length; i++)
- {
- scratchpad[i] = byteArrayRow[i];
- }
- setScratchpad(scratchpad);
- break;
- case SQLUDF_TF_CLOSE:
- break;
- case SQLUDF_TF_FINAL:
- break;
- }
- } // tableUDF
Add Comment
Please, Sign In to add comment