Subject | Re: [firebird-support] Get records based on the third portion of a version string |
---|---|
Author | Venus Software Operations |
Post date | 2015-05-10T11:56:52Z |
Thank you so much sir. Your original code gets me the result I
wanted but I had slightly different requirement, in that I just
wanted to send it a starting version string directly in the call to
the SP.
Please advise. My call and the updated SP as per my limited understanding of SPs follows. Though the SP compiles okay it raises an error when I run the command:
SELECT p.VERSION_NO FROM SP_VERSION_NOS (3, '.', '1.23.456.789') p;
Error:
---------------------------
An IBPP error occurred.
---------------------------
*** IBPP::SQLException ***
Context: Statement::Fetch
Message: isc_dsql_fetch failed.
SQL Message : -204
Undefined name
Engine Code : 335544853
Engine Message :
Invalid length parameter -1 to SUBSTRING. Negative integers are not allowed.
At procedure 'SP_VERSION_NOS' line: 48, col: 1
---------------------------
OK
---------------------------
SET TERM !! ;
ALTER PROCEDURE SP_VERSION_NOS(
PORTION smallint,
SEPARATOR char,
UPTO_VERSION varchar(80))
RETURNS (
VERSION_NO varchar(80)
)
AS
declare variable i smallint;
declare variable SEPARATOR_POS Integer;
declare variable VERSION_PORTION varchar(80);
declare variable VERSION_PORTION_INT integer;
declare variable EARLIER_TO integer;
BEGIN
FOR SELECT
a.cDoneVersion FROM tDevelopment a WHERE a.cDoneVersion <> '' INTO
:VERSION_NO
DO BEGIN
i = 1;
while (:PORTION > :i) do begin
select position(:SEPARATOR in :UPTO_VERSION) from RDB$DATABASE into :SEPARATOR_POS;
UPTO_VERSION = substring(:UPTO_VERSION from (:SEPARATOR_POS + 1) for char_length(UPTO_VERSION));
i = 1 + :i;
end
select position(:SEPARATOR in :UPTO_VERSION) from RDB$DATABASE into :SEPARATOR_POS;
i = 1 + :i;
UPTO_VERSION = substring(:UPTO_VERSION from 1 for :SEPARATOR_POS - 1);
EARLIER_TO = cast(:UPTO_VERSION as integer);
i = 1;
while (:PORTION > :i) do begin
select position(:SEPARATOR in :VERSION_NO) from RDB$DATABASE into :SEPARATOR_POS;
VERSION_NO = substring(:VERSION_NO from (:SEPARATOR_POS + 1) for char_length(VERSION_NO));
i = 1 + :i;
end
select position(:SEPARATOR in :VERSION_NO) from RDB$DATABASE into :SEPARATOR_POS;
i = 1 + :i;
VERSION_NO = substring(:VERSION_NO from 1 for :SEPARATOR_POS - 1);
VERSION_PORTION_INT = cast(:VERSION_NO as integer);
if(:EARLIER_TO >= :VERSION_PORTION_INT) then begin
SUSPEND;
end
END
END !!
SET TERM ; !!
On 10/05/2015 02:27 pm, LtColRDSChauhan rdsc1964@... [firebird-support] wrote:
Please advise. My call and the updated SP as per my limited understanding of SPs follows. Though the SP compiles okay it raises an error when I run the command:
SELECT p.VERSION_NO FROM SP_VERSION_NOS (3, '.', '1.23.456.789') p;
Error:
---------------------------
An IBPP error occurred.
---------------------------
*** IBPP::SQLException ***
Context: Statement::Fetch
Message: isc_dsql_fetch failed.
SQL Message : -204
Undefined name
Engine Code : 335544853
Engine Message :
Invalid length parameter -1 to SUBSTRING. Negative integers are not allowed.
At procedure 'SP_VERSION_NOS' line: 48, col: 1
---------------------------
OK
---------------------------
SET TERM !! ;
ALTER PROCEDURE SP_VERSION_NOS(
PORTION smallint,
SEPARATOR char,
UPTO_VERSION varchar(80))
RETURNS (
VERSION_NO varchar(80)
)
AS
declare variable i smallint;
declare variable SEPARATOR_POS Integer;
declare variable VERSION_PORTION varchar(80);
declare variable VERSION_PORTION_INT integer;
declare variable EARLIER_TO integer;
BEGIN
FOR SELECT
a.cDoneVersion FROM tDevelopment a WHERE a.cDoneVersion <> '' INTO
:VERSION_NO
DO BEGIN
i = 1;
while (:PORTION > :i) do begin
select position(:SEPARATOR in :UPTO_VERSION) from RDB$DATABASE into :SEPARATOR_POS;
UPTO_VERSION = substring(:UPTO_VERSION from (:SEPARATOR_POS + 1) for char_length(UPTO_VERSION));
i = 1 + :i;
end
select position(:SEPARATOR in :UPTO_VERSION) from RDB$DATABASE into :SEPARATOR_POS;
i = 1 + :i;
UPTO_VERSION = substring(:UPTO_VERSION from 1 for :SEPARATOR_POS - 1);
EARLIER_TO = cast(:UPTO_VERSION as integer);
i = 1;
while (:PORTION > :i) do begin
select position(:SEPARATOR in :VERSION_NO) from RDB$DATABASE into :SEPARATOR_POS;
VERSION_NO = substring(:VERSION_NO from (:SEPARATOR_POS + 1) for char_length(VERSION_NO));
i = 1 + :i;
end
select position(:SEPARATOR in :VERSION_NO) from RDB$DATABASE into :SEPARATOR_POS;
i = 1 + :i;
VERSION_NO = substring(:VERSION_NO from 1 for :SEPARATOR_POS - 1);
VERSION_PORTION_INT = cast(:VERSION_NO as integer);
if(:EARLIER_TO >= :VERSION_PORTION_INT) then begin
SUSPEND;
end
END
END !!
SET TERM ; !!
On 10/05/2015 02:27 pm, LtColRDSChauhan rdsc1964@... [firebird-support] wrote:
>smallint,
> Please try :
>
> SET TERM !! ; alter PROCEDURE SP_VERSION_NOS( PORTION
> SEPARATOR char, EARLIER_TO integer) RETURNS ( VERSION_NOvarchar(80)
> ) AS declare variable i smallint; declare variableSEPARATOR_POS
> Integer; declare variable VERSION_PORTION varchar(80);declare
> variable VERSION_PORTION_INT integer; BEGIN FOR SELECTa.VERSION_NO
> FROM VERSION_NOS a INTO :VERSION_NO DO BEGIN i = 1; while(:PORTION
> > :i) do begin select position(:SEPARATOR in :VERSION_NO)from
> RDB$DATABASE into :SEPARATOR_POS; VERSION_NO =substring(:VERSION_NO
> from (:SEPARATOR_POS + 1) for char_length(VERSION_NO)); i = 1+ :i;
> end select position(:SEPARATOR in :VERSION_NO) fromRDB$DATABASE
> into :SEPARATOR_POS; i = 1 + :i; VERSION_NO =substring(:VERSION_NO
> from 1 for :SEPARATOR_POS - 1);if(:EARLIER_TO
>
> VERSION_PORTION_INT = cast(:VERSION_NO as integer);
> >= :VERSION_PORTION_INT) then begin SUSPEND; end ENDp; */
>
> /* SELECT p.VERSION_NO FROM SP_VERSION_NOS ('3', '.', '456')
> END!! SET TERM ; !!string
>
> On Sun, May 10, 2015 at 12:08 PM, venussoftop@...
> <mailto:venussoftop@...> [firebird-support]
> <firebird-support@yahoogroups.com
> <mailto:firebird-support@yahoogroups.com>> wrote:
>
>
>
> Hi all
>
> I was wondering if there was a way to get a portion of a
> based on a separator character. What I needed to do was wantto
> bring out a part of the version number.on
>
> 1.23.456.789
>
> I want to get just the third portion, 456. So I could query
> strings that have a version number with the third portionless than
> or equal to 456. Thus all records which may contain-------------------------
>
> 1.1.55.0 1.15.450.688
>
> Hope I was able to explain.
>
> Please advise.
>
> Thanks and regards Bhavbhuti
>
>
>
>
> -- Regards, Lt Col (Retd) Rajiv D.S. Chauhan
> in.linkedin.com/in/ltcolrdschauhan
> <http://in.linkedin.com/in/ltcolrdschauhan>
> _____________________________
> Posted by: LtColRDSChauhan <rdsc1964@...>