654: begin
655: i := findNextBindVariable(gridName,null);
656: while i is not null loop
657: if bindVariables(i).variableDataType = 'C' then
658: dbms_sql.bind_variable(tableDefs(tableIndex).SQLCursor,bindVariables(i).variableName,bindVariables(i).variableCharValue);
659: elsif bindVariables(i).variableDataType = 'D' then
660: dbms_sql.bind_variable(tableDefs(tableIndex).SQLCursor,bindVariables(i).variableName,bindVariables(i).variableDateValue);
661: elsif bindVariables(i).variableDataType = 'N' then
662: dbms_sql.bind_variable(tableDefs(tableIndex).SQLCursor,bindVariables(i).variableName,bindVariables(i).variableNumberValue);
656: while i is not null loop
657: if bindVariables(i).variableDataType = 'C' then
658: dbms_sql.bind_variable(tableDefs(tableIndex).SQLCursor,bindVariables(i).variableName,bindVariables(i).variableCharValue);
659: elsif bindVariables(i).variableDataType = 'D' then
660: dbms_sql.bind_variable(tableDefs(tableIndex).SQLCursor,bindVariables(i).variableName,bindVariables(i).variableDateValue);
661: elsif bindVariables(i).variableDataType = 'N' then
662: dbms_sql.bind_variable(tableDefs(tableIndex).SQLCursor,bindVariables(i).variableName,bindVariables(i).variableNumberValue);
663: else
664: null;
658: dbms_sql.bind_variable(tableDefs(tableIndex).SQLCursor,bindVariables(i).variableName,bindVariables(i).variableCharValue);
659: elsif bindVariables(i).variableDataType = 'D' then
660: dbms_sql.bind_variable(tableDefs(tableIndex).SQLCursor,bindVariables(i).variableName,bindVariables(i).variableDateValue);
661: elsif bindVariables(i).variableDataType = 'N' then
662: dbms_sql.bind_variable(tableDefs(tableIndex).SQLCursor,bindVariables(i).variableName,bindVariables(i).variableNumberValue);
663: else
664: null;
665: -- Unknown datatype, should never get here
666: end if;
667: i := findNextBindVariable(gridName,i);
668: end loop;
669: exception
670: when others then
671: if dbms_sql.is_open(tableDefs(tableIndex).SQLCursor) then
672: dbms_sql.close_cursor(tableDefs(tableIndex).SQLCursor);
673: tableDefs(tableIndex).SQLCursor := null;
674: end if;
675: raise;
668: end loop;
669: exception
670: when others then
671: if dbms_sql.is_open(tableDefs(tableIndex).SQLCursor) then
672: dbms_sql.close_cursor(tableDefs(tableIndex).SQLCursor);
673: tableDefs(tableIndex).SQLCursor := null;
674: end if;
675: raise;
676: -- handleErrors(INTERNAL_ERROR,'handleBindVariables',gridName,
699: -- If we don't have a handle to the cursor or it is closed for some reason
700: -- we reopen it and make sure that the sql statement will be parsed as well
701: -- as having any bind variables bound
702: if tableDefs(tableIndex).SQLCursor is null
703: or not dbms_sql.is_open(tableDefs(tableIndex).SQLCursor) then
704: tableDefs(tableIndex).SQLCursor := dbms_sql.open_cursor;
705: tableDefs(tableIndex).hasBindVarsChanged := 'T';
706: tableDefs(tableIndex).hasWhereClauseChanged := 'T';
707: end if;
700: -- we reopen it and make sure that the sql statement will be parsed as well
701: -- as having any bind variables bound
702: if tableDefs(tableIndex).SQLCursor is null
703: or not dbms_sql.is_open(tableDefs(tableIndex).SQLCursor) then
704: tableDefs(tableIndex).SQLCursor := dbms_sql.open_cursor;
705: tableDefs(tableIndex).hasBindVarsChanged := 'T';
706: tableDefs(tableIndex).hasWhereClauseChanged := 'T';
707: end if;
708:
713:
714: -- If we fail to build up the sql statement we close the
715: -- cursor straight away.
716: if prepareSQL(gridName,tableIndex) = false then
717: dbms_sql.close_cursor(tableDefs(tableIndex).SQLCursor);
718: tableDefs(tableIndex).SQLCursor := null;
719: return null;
720: -- If the SQL statement is OK, we parse and define the columns
721: else
718: tableDefs(tableIndex).SQLCursor := null;
719: return null;
720: -- If the SQL statement is OK, we parse and define the columns
721: else
722: dbms_sql.parse(tableDefs(tableIndex).SQLCursor, tableDefs(tableIndex).SQLStatement, dbms_sql.native);
723: ----------------------------------------------------------
724: for i in 1..temp_columnDefs.count loop
725: --dbms_output.put_line('i si ' ||i||columnDefs(i).data_type_code);
726: if temp_columnDefs(i).data_type_code = 'C' then
723: ----------------------------------------------------------
724: for i in 1..temp_columnDefs.count loop
725: --dbms_output.put_line('i si ' ||i||columnDefs(i).data_type_code);
726: if temp_columnDefs(i).data_type_code = 'C' then
727: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor,j, charColVal, 4000);
728: elsif temp_columnDefs(i).data_type_code = 'N' then
729: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor,j, NumberColVal);
730: if temp_columnDefs(i).display_format_type_code = 'CUR' then
731: j := j + 1;
725: --dbms_output.put_line('i si ' ||i||columnDefs(i).data_type_code);
726: if temp_columnDefs(i).data_type_code = 'C' then
727: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor,j, charColVal, 4000);
728: elsif temp_columnDefs(i).data_type_code = 'N' then
729: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor,j, NumberColVal);
730: if temp_columnDefs(i).display_format_type_code = 'CUR' then
731: j := j + 1;
732: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor, j, charColVal, 4000);
733: end if;
728: elsif temp_columnDefs(i).data_type_code = 'N' then
729: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor,j, NumberColVal);
730: if temp_columnDefs(i).display_format_type_code = 'CUR' then
731: j := j + 1;
732: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor, j, charColVal, 4000);
733: end if;
734: elsif temp_columnDefs(i).data_type_code = 'D' then
735: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor, j, dateColVal);
736: elsif temp_columnDefs(i).data_type_code = 'I' then
731: j := j + 1;
732: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor, j, charColVal, 4000);
733: end if;
734: elsif temp_columnDefs(i).data_type_code = 'D' then
735: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor, j, dateColVal);
736: elsif temp_columnDefs(i).data_type_code = 'I' then
737: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor,j, charColVal, 4000);
738: if temp_columnDefs(i).image_description_col is not NULL then
739: j := j + 1;
733: end if;
734: elsif temp_columnDefs(i).data_type_code = 'D' then
735: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor, j, dateColVal);
736: elsif temp_columnDefs(i).data_type_code = 'I' then
737: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor,j, charColVal, 4000);
738: if temp_columnDefs(i).image_description_col is not NULL then
739: j := j + 1;
740: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor,j, CharColVal, 4000);
741: end if;
736: elsif temp_columnDefs(i).data_type_code = 'I' then
737: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor,j, charColVal, 4000);
738: if temp_columnDefs(i).image_description_col is not NULL then
739: j := j + 1;
740: dbms_sql.define_column(tableDefs(tableIndex).SQLCursor,j, CharColVal, 4000);
741: end if;
742: end if;
743: j := j + 1;
744: end loop;
759: end if;
760:
761: -- If we need to refresh the query for whatever reason -> execute the query
762: if tableDefs(tableIndex).refreshFlag = 'T' then
763: ignore := dbms_sql.execute(tableDefs(tableIndex).SQLCursor);
764: tableDefs(tableIndex).refreshFlag := 'F';
765: end if;
766:
767: -- Fetch one row and write the result to the stream
764: tableDefs(tableIndex).refreshFlag := 'F';
765: end if;
766:
767: -- Fetch one row and write the result to the stream
768: rows := dbms_sql.fetch_rows(tableDefs(tableIndex).SQLCursor);
769: if rows > 0 then
770: jtf_dbstream_utils.clearOutputStream;
771:
772: /* the retrieved values are no longer only varchar2
770: jtf_dbstream_utils.clearOutputStream;
771:
772: /* the retrieved values are no longer only varchar2
773: for i in 1..tableDefs(tableIndex).colCount loop
774: dbms_sql.column_value(tableDefs(tableIndex).SQLCursor, i, colVal);
775: jtf_dbstream_utils.writeString(colVal);
776: end loop;
777: */
778: -----------------------------------------------
779: j := 1;
780: for i in 1..temp_columnDefs.count loop
781: --dbms_output.put_line('i value is '||i||' datatype is '||columnDefs(i).data_type_code);
782: if temp_columnDefs(i).data_type_code = 'C' then
783: dbms_sql.column_value(tableDefs(tableIndex).SQLCursor, j, CharColVal);
784: jtf_dbstream_utils.writeString(charColVal);
785: elsif temp_columnDefs(i).data_type_code = 'N' then
786: dbms_sql.column_value(tableDefs(tableIndex).SQLCursor,j, NumberColVal);
787: if temp_columnDefs(i).display_format_mask is not null then
782: if temp_columnDefs(i).data_type_code = 'C' then
783: dbms_sql.column_value(tableDefs(tableIndex).SQLCursor, j, CharColVal);
784: jtf_dbstream_utils.writeString(charColVal);
785: elsif temp_columnDefs(i).data_type_code = 'N' then
786: dbms_sql.column_value(tableDefs(tableIndex).SQLCursor,j, NumberColVal);
787: if temp_columnDefs(i).display_format_mask is not null then
788: jtf_dbstream_utils.writeString(to_char(NumberColVal,temp_columnDefs(i).display_format_mask));
789: elsif temp_columnDefs(i).display_format_type_code = 'CUR'
790: and temp_columnDefs(i).db_currency_code_col is not null then
788: jtf_dbstream_utils.writeString(to_char(NumberColVal,temp_columnDefs(i).display_format_mask));
789: elsif temp_columnDefs(i).display_format_type_code = 'CUR'
790: and temp_columnDefs(i).db_currency_code_col is not null then
791: j := j + 1;
792: dbms_sql.column_value(tableDefs(tableIndex).SQLCursor, j, charColVal);
793: jtf_dbstream_utils.writeCurrency(NumberColVal, charColVal);
794: else
795: jtf_dbstream_utils.writeNumber(NumberColVal);
796: end if;
794: else
795: jtf_dbstream_utils.writeNumber(NumberColVal);
796: end if;
797: elsif temp_columnDefs(i).data_type_code = 'D' then
798: dbms_sql.column_value(tableDefs(tableIndex).SQLCursor, j, dateColVal);
799: if temp_columnDefs(i).display_format_type_code = 'DAT' then
800: jtf_dbstream_utils.writeDate(DateColVal);
801: else
802: jtf_dbstream_utils.writeDateTime(DateColVal);
801: else
802: jtf_dbstream_utils.writeDateTime(DateColVal);
803: end if;
804: elsif temp_columnDefs(i).data_type_code = 'I' then
805: dbms_sql.column_value(tableDefs(tableIndex).SQLCursor, j, CharColVal);
806: imageCharColVal := CharColVal;
807: if temp_columnDefs(i).image_description_col is not NULL then
808: j := j + 1;
809: dbms_sql.column_value(tableDefs(tableIndex).SQLCursor, j, CharColVal);
805: dbms_sql.column_value(tableDefs(tableIndex).SQLCursor, j, CharColVal);
806: imageCharColVal := CharColVal;
807: if temp_columnDefs(i).image_description_col is not NULL then
808: j := j + 1;
809: dbms_sql.column_value(tableDefs(tableIndex).SQLCursor, j, CharColVal);
810: jtf_dbstream_utils.writeString(ImageCharColVal||IMAGE_SEPARATOR||CharColVal);
811: else
812: jtf_dbstream_utils.writeString(ImageCharColVal||IMAGE_SEPARATOR);
813: end if;
817: -------------------------------------------------------------
818: else
819: -- We don't close the cursor nowadays, only if the grid is initialized
820: -- with a different datasource will it be closed and reopened
821: -- dbms_sql.close_cursor(tableDefs(tableIndex).SQLCursor);
822: return null;
823: end if;
824: -- CURSOR MGMT REWRITE END
825: if jtf_dbstream_utils.isLongOutputStream then
829: end if;
830: return jtf_dbstream_utils.getOutputStream;
831: exception
832: when others then
833: if dbms_sql.is_open(tableDefs(tableIndex).SQLCursor) then
834: dbms_sql.close_cursor(tableDefs(tableIndex).SQLCursor);
835: tableDefs(tableIndex).SQLCursor := null;
836: end if;
837: raise;
830: return jtf_dbstream_utils.getOutputStream;
831: exception
832: when others then
833: if dbms_sql.is_open(tableDefs(tableIndex).SQLCursor) then
834: dbms_sql.close_cursor(tableDefs(tableIndex).SQLCursor);
835: tableDefs(tableIndex).SQLCursor := null;
836: end if;
837: raise;
838: -- handleErrors(INTERNAL_ERROR,'execSQL',gridName,null
925: end if;
926: -- CURSOR MGMR REWRITE
927: -- if tableDefs(tableIndex).moreRowsExists = 'T'
928: -- and tableDefs(tableIndex).SQLCursor is not null
929: -- and dbms_sql.is_open(tableDefs(tableIndex).SQLCursor) then
930: -- dbms_sql.close_cursor(tableDefs(tableIndex).SQLCursor);
931: -- end if;
932: -- tableDefs(tableIndex).SQLCursor := null;
933: -- CURSOR MGMR REWRITE END
926: -- CURSOR MGMR REWRITE
927: -- if tableDefs(tableIndex).moreRowsExists = 'T'
928: -- and tableDefs(tableIndex).SQLCursor is not null
929: -- and dbms_sql.is_open(tableDefs(tableIndex).SQLCursor) then
930: -- dbms_sql.close_cursor(tableDefs(tableIndex).SQLCursor);
931: -- end if;
932: -- tableDefs(tableIndex).SQLCursor := null;
933: -- CURSOR MGMR REWRITE END
934: tableDefs(tableIndex).moreRowsExists := 'T';
2050: -- its initial state
2051: --if tableDefs(tableIndex).moreRowsExists = 'T'
2052: -- 4282028
2053: if tableDefs(tableIndex).SQLCursor is not null
2054: and dbms_sql.is_open(tableDefs(tableIndex).SQLCursor) then
2055: dbms_sql.close_cursor(tableDefs(tableIndex).SQLCursor);
2056: end if;
2057:
2058: -- if this function is being called then it passes server validation
2051: --if tableDefs(tableIndex).moreRowsExists = 'T'
2052: -- 4282028
2053: if tableDefs(tableIndex).SQLCursor is not null
2054: and dbms_sql.is_open(tableDefs(tableIndex).SQLCursor) then
2055: dbms_sql.close_cursor(tableDefs(tableIndex).SQLCursor);
2056: end if;
2057:
2058: -- if this function is being called then it passes server validation
2059: -- ideally this procedure/function should be called after remove all bind