Um pequeno exemplo de uma store procedure em Firebird

February 9th, 2009

Aqui vc encontra um exemplo de uma procedure que ao mesmo

tempo que dá entrada ou saída no saldo de estoque por lote/validade já

lança numa tabela de registros os itens que entraram ou saíram para

uma posterior auditoria.

CREATE OR ALTER PROCEDURE AJUSTA_ESTOQUE_LOTE (
vis_produto integer,
vis_filial integer,
vis_setor integer,
vis_setordestino integer,
vop varchar(2),
vqtde numeric(18,3),
vlote varchar(30),
vvalidade date,
vis_orcamento double precision,
vis_usuario integer)
returns (
r integer)
as
declare variable id integer;
declare variable id2 integer;
declare variable id3 integer;
declare variable sentenca varchar(3000);
declare variable nomecampo varchar(32);
declare variable data date;
declare variable hora time;
declare variable mes varchar(3);
declare variable ano smallint;
declare variable mes_int smallint;
begin
r=0;
id=0;
id2=0;

if (:vis_setor IS NULL) then
suspend;

sentenca =
’select
case
when extract(month from cast(”’||:vvalidade||”’ as date))=1  then ”JAN”
when extract(month from cast(”’||:vvalidade||”’ as date))=2  then ”FEV”
when extract(month from cast(”’||:vvalidade||”’ as date))=3  then ”MAR”
when extract(month from cast(”’||:vvalidade||”’ as date))=4  then ”ABR”
when extract(month from cast(”’||:vvalidade||”’ as date))=5  then ”MAI”
when extract(month from cast(”’||:vvalidade||”’ as date))=6  then ”JUN”
when extract(month from cast(”’||:vvalidade||”’ as date))=7  then ”JUL”
when extract(month from cast(”’||:vvalidade||”’ as date))=8  then ”AGO”
when extract(month from cast(”’||:vvalidade||”’ as date))=9  then ”SET”
when extract(month from cast(”’||:vvalidade||”’ as date))=10  then ”OUT”
when extract(month from cast(”’||:vvalidade||”’ as date))=11  then ”NOV”
when extract(month from cast(”’||:vvalidade||”’ as date))=12  then ”DEZ”
end,
extract(month from cast(”’||:vvalidade||”’ as date)),
extract(year from cast(”’||:vvalidade||”’ as date))
from RDB$DATABASE’;

execute statement Sentenca into :mes, :mes_int, :ano;

select first 1 pe.id_produtoloteestoque from produtos_lote_estoque pe
where pe.is_produto=:vis_produto
and pe.is_filial=:vis_filial
and pe.is_setor=:vis_setor
and pe.lote=:vlote
and pe.validade=:vvalidade
into: id;

if (vop=’T') then
begin
select first 1 pe.id_produtoloteestoque from produtos_lote_estoque pe
where pe.is_produto=:vis_produto
and pe.is_filial=:vis_filial
and pe.is_setor=:vis_setordestino
and pe.lote=:vlote
and pe.validade=:vvalidade
into: id2;
end

/* Se não encontrou produtos_Estoque, incluir um registro */
if (id<=0) then
begin
nomeCampo=’GEN_ID_PRODUTOLOTEESTOQUE’;
Sentenca = ’select cast(gen_id(’ || :nomeCampo || ‘, 1) as integer) from RDB$DATABASE’;
execute statement Sentenca into :ID;

insert into PRODUTOS_LOTE_ESTOQUE
(ID_PRODUTOLOTEESTOQUE,IS_FILIAL,IS_SETOR,IS_PRODUTO,LOTE,VALIDADE,ENTRADA,SAIDA,SALDO,MES,ANO, MES_INT)
VALUES (:ID, :vis_filial, :vis_setor, :vis_produto, :vlote, :vvalidade, 0, 0, 0,:mes,:ano,:mes_int);
end

if ((id2<=0) and (:vop=’T')) then
begin
nomeCampo=’GEN_ID_PRODUTOLOTEESTOQUE’;
Sentenca = ’select cast(gen_id(’ || :nomeCampo || ‘, 1) as integer) from RDB$DATABASE’;
execute statement Sentenca into :ID2;

insert into PRODUTOS_LOTE_ESTOQUE
(ID_PRODUTOLOTEESTOQUE,IS_FILIAL,IS_SETOR,IS_PRODUTO,LOTE,VALIDADE,ENTRADA,SAIDA,SALDO,MES,ANO, MES_INT)
VALUES (:ID2, :vis_filial, :vis_setordestino, :vis_produto, :vlote, :vvalidade, 0, 0, 0,:mes,:ano,:mes_int);
end

if (:vop=’XX’)  then
begin
update produtos_lote_estoque pe
set
pe.entrada=:vqtde,
pe.saldo=:vqtde
where pe.id_produtoloteestoque=:id;
r=1;
end

if ((:vop=’E') or (:vop=’DV’))  then
begin
update produtos_lote_estoque pe
set
pe.entrada=pe.entrada+:vqtde,
pe.saldo=pe.saldo+:vqtde
where pe.id_produtoloteestoque=:id;
r=1;
end

if ((:vop=’S') or (:vop=’DC’) or (:vop=’SA’) or (:vop=’SI’) or (:vop=’SG’)) then
begin
update produtos_lote_estoque pe
set
pe.saida=pe.saida+:vqtde,
pe.saldo=pe.saldo-:vqtde
where pe.id_produtoloteestoque=:id;
r=1;
end

if (:vop=’T') then
begin
update produtos_lote_estoque pe
set
pe.saida=pe.saida+:vqtde,
pe.saldo=pe.saldo-:vqtde
where pe.id_produtoloteestoque=:id;

update produtos_lote_estoque pe
set
pe.entrada=pe.entrada+:vqtde,
pe.saldo=pe.saldo+:vqtde
where pe.id_produtoloteestoque=:id2;
r=1;
end

nomeCampo=’GEN_ID_ITEMLOTEMOVIMENTACAO’;
Sentenca = ’select cast(gen_id(’ || :nomeCampo || ‘, 1) as integer) from RDB$DATABASE’;
execute statement Sentenca into :ID3;

Sentenca =’select current_date from RDB$DATABASE’;
execute statement Sentenca into :data;

Sentenca =’select current_time from RDB$DATABASE’;
execute statement Sentenca into :hora;

insert into ITENS_LOTE_MOVIMENTACOES
(ID_ITEMLOTEMOVIMENTACAO, IS_PRODUTOLOTEESTOQUE, IS_PRODUTO, QTDE, VALIDADE,
LOTE, IS_FILIAL, IS_SETOR, OP, IS_ORCAMENTO, DATA_LOTE, HORARIO_LOTE, IS_USUARIO, MES, ANO, MES_INT)
VALUES (:id3, :id, :vis_produto, :vqtde,:vvalidade,:vlote,:vis_filial,:vis_setor,:vop,
:vis_orcamento,:data,:hora,:vis_usuario,:mes, :ano, :mes_int);

suspend;
end

Autor: Farnetani

Utilizando o Execute Statement em uma procedure selecionável no Firebird.

February 9th, 2009

1. Esta seria uma procedure que busca em uma tabela recebendo os parâmetros até de ordenação pelo delphi vc pode chamar ela

SELECT
OPCODIGOLOGON AS CODIGO,
OPLOGON AS LOGON,
OPSENHA AS SENHA,
OPNIVEL AS NIVEL
FROM SP_LOGON_SELECIONA(0,”,”,1,’SIM’,’2,1 DESC’)

O Interessante é que vc executa a Store com o parâmetro que vc quiser aí vc pode simplesmente consultar por todos campos ou só por um, ordenando por um vários de ordem crescente ou decrescente, ficando de acordo com o gosto do cliente.

CREATE PROCEDURE SP_LOGON_SELECIONA (
IPCODIGOLOGON INTEGER,
IPLOGON VARCHAR(20),
IPSENHA VARCHAR(10),
IPNIVEL INTEGER,
IPPREENCHACAMPOS VARCHAR(3),
IPORDENAR VARCHAR(1000))
RETURNS (
OPCODIGOLOGON INTEGER,
OPLOGON VARCHAR(20),
OPSENHA VARCHAR(10),
OPNIVEL INTEGER)
AS
DECLARE VARIABLE VAND VARCHAR(1);
DECLARE VARIABLE VSQL VARCHAR(1000);
BEGIN
– Aqui é o caso do And se já tem algum campo ele coloca o AND se não ele não coloca
VAND = ‘N’;

– Começo do SQL aqui em cima vai o Select e o FROM
VSQL = ‘SELECT CODIGOLOGON, LOGON, SENHA, NIVEL’;
VSQL = VSQL || ‘ FROM LOGON’;

–Do Jeito que vem do Delphi transformo para NULL
IF (:IPLOGON = ”) THEN
IPLOGON = NULL;
IF (:IPSENHA = ”) THEN
IPSENHA = NULL;
IF (:IPNIVEL = 0) THEN
IPNIVEL = NULL;
IF (:IPCODIGOLOGON = 0) THEN
IPCODIGOLOGON = NULL;
IF ((:IPORDENAR = ”) OR (:IPORDENAR IS NULL)) THEN
IPORDENAR = ‘1′;
IF (:IPPREENCHACAMPOS = ”) THEN
IPPREENCHACAMPOS = ‘SIM’;

–Se precisar ser tudo obrigatório ou se fazer parte dele dá o erro aqui
IF ( :IPPREENCHACAMPOS = ‘SIM’) THEN
BEGIN
IF ( (:IPLOGON IS NULL) AND (:IPSENHA IS NULL) AND (:IPNIVEL IS NULL)) THEN
BEGIN
EXCEPTION ERRO ‘PREENCHA OS CAMPOS OBRIGATÓRIOS’;
EXIT;
END
ELSE
BEGIN
–Aqui coloca o WHERE
VSQL = VSQL || ‘ WHERE ‘;

–Começa a conferencia de campos
IF (:IPLOGON IS NOT NULL) THEN
BEGIN
–Estou usando o Like as 4 aspas é para colocar uma aspas no parametro ex: Logon like ‘%PARAMETRO%’
VSQL = VSQL || ‘ LOGON LIKE ‘ || ”” || ‘%’ || :IPLOGON || ‘%’ || ””;
VAND = ‘S’;
END
–Aqui começa a verificação do And

IF (:IPSENHA IS NOT NULL) THEN
BEGIN
IF (:VAND = ‘S’) THEN
VSQL = VSQL || ‘ AND’;

VSQL = VSQL || ‘ SENHA LIKE ‘ || ”” || ‘%’ || :IPSENHA || ‘%’ || ””;

VAND = ‘S’;
END

IF (:IPNIVEL IS NOT NULL) THEN
BEGIN
IF (:VAND = ‘S’) THEN
VSQL = VSQL || ‘ AND’;

VSQL = VSQL || ‘ NIVEL = ‘ || :IPNIVEL;

VAND = ‘S’;
END

–Verifico a Ordenação que foi passada via Parametro tambem
VSQL = VSQL || ‘ ORDER BY ‘ || :IPORDENAR;

–Uso o For Execute Stamente pois pode ser que seja mais de uma linha que será retornado
FOR
EXECUTE STATEMENT VSQL INTO :OPCODIGOLOGON, :OPLOGON, :OPSENHA, :OPNIVEL
DO

– Usa o SUSPEND todas as vezes que retornar valor
SUSPEND;
END
END
End

Fonte: http://gustavohenriquephn.wordpress.com/2008/03/26/utilizando-o-execute-statement-em-uma-procedure-selecionavel-no-firebird/

Simplified BlazeDS and JMS

January 31st, 2009

http://mmartinsoftware.blogspot.com/2008/05/simplified-blazeds-and-jms.html

Delphi for PHP + extjs

January 31st, 2009

http://www.qadram.com/vcl4php/movies/extjs/extjs_integration.html

Ferramenta IDE Flex

January 31st, 2009

http://flexible.riaforge.org/

Livros Free

January 31st, 2009

http://www.flazx.com/

Blog Flex ótimo

December 28th, 2008

http://msdevstudio.com/blog/tag/flex/

Flex Links

December 21st, 2008

http://blog.flexexamples.com/

http://examples.adobe.com/flex3/componentexplorer/explorer.html

Symbian links

December 16th, 2008

http://developer.uiq.com/devtools_uiqsdk.html

http://developer.symbian.com/main/tools_and_sdks/sdks/uiq/index.jsp

http://developer.symbian.com/main/tools_and_sdks/sdks/s60/index.jsp

http://developer.symbian.com/main/documentation/symbian_cpp/adding_a_ui/index.jsp

http://www.forum.nokia.com/info/sw.nokia.com/id/4a7149a5-95a5-4726-913a-3c6f21eb65a5/S60-SDK-0616-3.0-mr.html

Documentação: http://developer.symbian.com/main/documentation/symbian_cpp/

http://developer.symbian.com/main/documentation/example_app_code/java/index.jsp (exemplos em java)

http://developer.symbian.com/main/getstarted/

http://developer.symbian.com/main/documentation/index.jsp

http://developer.symbian.com/forum/index.jspa

http://www.simkin.co.uk/

http://developer.symbian.com/main/documentation/sdl/index.jsp

http://en.wikipedia.org/wiki/Ruby_programming_language (ruby)

Ruby for Symbian OS

December 16th, 2008

Ruby for Symbian OS

October 2008: Symbian Research and Pragmaticomm are pleased to announce the availability of Ruby v1.9 for Symbian OS.

Introduction

Symbian is releasing Ruby for Symbian OS to the Open Source software developer community.

Ruby is a powerful dynamic language that reaches the heights of the pure Object Oriented Programming paradigm and gives a wealth of language features like exceptions, blocks, closures, regular expressions, collections, meta-classing and much more. Ruby is enjoying a growing popularity in different developer communities.

Ruby for Symbian OS brings the power of the Ruby programming language to the Symbian ecosystem under the terms of this Licence Agreement.

Ruby 1.9 Distribution

Symbian Research has been extended the initial port of Ruby v1.9 which was carried out under the auspices of the GREDIA EU-funded project (FP6 34363 - Grid enabled access to Rich mEDIA content)  by Pragmaticomm.

Downloads

Ruby 1.9 binaries, with release notes and basic instructions Example scripts

Please note that this software is of very early beta quality, and although the current implementation is reasonably stable, potential developers and contributors should be aware of certain outstanding issues.

This Ruby 1.9 implementation replaces the earlier Ruby 1.8 implementation.

More information on the Ruby programming language can be found at:

Source Code

A read-only source-code repository for this release can be found on the Pragmaticomm’s source server.

This repository also contains the earlier version of the Ruby 1.9 VM for Symbian OS, developed for use in the GREDIA project - the Symbian Research release above has augmented the earlier GREDIA version with:

  • A new, more user friendly launcher
  • Extensions that enable to use of camera and video functionality for Ruby programmers
  • A prototype implementation for adding dynamic extensions to Ruby

Feedback and Discussion Forum

We’d love to hear what you think of Ruby and how we can improve the implementation on Symbian OS. There’s lots more work to do so if you want to get involved please get in touch.

There is an SDN forum where you can discuss Ruby issues and future work. Topics in this forum can relate to various runtime environments and languages, so please remember to tag any Ruby-related contributions with the label “Ruby”. If you don’t already have access to SDN then you will need to register before using the forum.

Fonte: http://developer.symbian.com/main/community/open_source_projects/ruby/index.jsp