tag:blogger.com,1999:blog-34438541626070090762023-11-15T13:52:19.450-03:00asfernandesThis blog has a new home: https://asfernandes.github.ioAdrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.comBlogger33125tag:blogger.com,1999:blog-3443854162607009076.post-62779326279228204732016-09-07T22:50:00.004-03:002016-09-07T22:53:00.379-03:00New homeThis blog has a new home. Please update bookmarks and feeds to <a href="https://asfernandes.github.io/">https://asfernandes.github.io</a>Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-79749177177657353402015-02-11T21:41:00.000-02:002015-02-11T21:41:23.758-02:00JavaScript x Java - closures e lambdas<div style="text-align: justify;">
Em geral as linguagens de programação são bem parecidas e por esse motivo acho fácil aprender novas linguagens. E o que dizer então quando uma se chama Java e a outra JavaScript? :)</div>
<div style="text-align: justify;">
Ultimamente tenho programado bastante em JavaScript. Apesar de não conhecer ainda todos os detalhes da linguagem, tenho me virado bem, porém, hoje perdi um certo tempo programando em JavaScript como se estivesse programando em Java.</div>
<div style="text-align: justify;">
Simplificação do código em JavaScript:</div>
<span style="font-family: Courier New, Courier, monospace;">var i = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace;">var ar = [];</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">while (i < 2)</span><br />
<span style="font-family: Courier New, Courier, monospace;">{</span><br />
<span style="font-family: Courier New, Courier, monospace;"> var n = i;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> </span><br />
<span style="font-family: Courier New, Courier, monospace;"> ar.push(function() {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> return n;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> });</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> ++i;</span><br />
<span style="font-family: Courier New, Courier, monospace;">}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">console.log(ar[0]()); // 1</span><br />
<span style="font-family: Courier New, Courier, monospace;">console.log(ar[1]()); // 1</span><br />
<div>
<br /></div>
<div style="text-align: justify;">
Neste trecho de código acima, esperava que imprimisse as linhas 0 e 1, como no código abaixo equivalente em Java, porém imprime 1 e 1.</div>
<div style="text-align: justify;">
Código em Java (8) supostamente equivalente:</div>
<div>
<div>
<span style="font-family: Courier New, Courier, monospace;">int i = 0;</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">ArrayList<Supplier<Integer>> ar = new ArrayList<>();</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: 'Courier New', Courier, monospace;">while (i < 2</span><span style="font-family: Courier New, Courier, monospace;">)</span><br />
<span style="font-family: Courier New, Courier, monospace;">{</span></div>
<span style="font-family: Courier New, Courier, monospace;"> int n = i;<br /><br /> ar.add(() -> n);<br /> ++i;<br />}<br /><br />System.out.println(ar.get(0).get()); // 0<br />System.out.println(ar.get(1).get()); // 1<br /></span></div>
<div style="text-align: justify;">
Enquanto que o código Java carrega o valor de "n" ("closure" - entre aspas porque no Java isso não é bem uma closure) para a expressão lambda com o valor de cada iteração do while, o código JavaScript carrega apenas uma variável "n", que é alterada em cada iteração. Isso acontece porque as regras de escopo de variáveis do JavaScript são totalmente diferentes de Java.</div>
<div style="text-align: justify;">
O código JavaScript abaixo que é equivalente ao código Java e retorna 0 e 1:</div>
<span style="font-family: Courier New, Courier, monospace;"><br />var i = 0;<br />var ar = [];<br /><br />while (i < 2)<br />{<br /> (function(n) {<br /> ar.push(function() {<br /> return n;<br /> })<br /> })(i);</span><div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span><div>
<span style="font-family: Courier New, Courier, monospace;"> ++i;<br />}<br /><br />console.log(ar[0]()); // 0<br />console.log(ar[1]()); // 1<br /><br /></span><div style="text-align: justify;">
Passando "i" para o parâmetro "n" da função anônima, criamos um novo escopo.</div>
</div>
</div>
Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-72579937853352228692015-01-22T13:22:00.001-02:002015-01-22T13:43:26.756-02:00Corrigindo schemas do Web Service Distribuição de DF-e da NF-eNa <a href="https://www.google.com.br/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CB8QFjAA&url=http%3A%2F%2Fwww.nfe.fazenda.gov.br%2Fportal%2FexibirArquivo.aspx%3Fconteudo%3D2Z%2520kcHOdpHs%3D&ei=Qf7AVMahIYXiggTzvIGQCA&usg=AFQjCNGQhPOg75_Yz9ef4mHmrvye8Fip2g&sig2=JfGl0mLlOas2WnKKyzkl-g&bvm=bv.83829542,d.eXY" target="_blank">Nota Técnica 2014/002</a> da Nota Fiscal Eletrônica, o governo <strike>brasileiro</strike> do PT, <strike>por falta do que fazer</strike> com o intuito de evoluir o sistema, substituiu o web service de consulta de NF-e emitidas por terceiros pelo web service de distribuição de documentos fiscais.<br />
<br />
Definiram que a partir de 06/10/2014 o novo web service já estaria funcionando no ambiente de produção, enquanto o antigo seria desativado em 02/02/2015. Estava tentando há duas semanas usar o novo web service e ele ainda não funcionava. Hoje consegui.<br />
<br />
O web service retornou resposta, mas é claro, resposta errada que não é validada pelo próprio <a href="http://www.nfe.fazenda.gov.br/portal/exibirArquivo.aspx?conteudo=cI%202zLXpcts=" target="_blank">schema</a> distribuído por eles. Como uso Java com JAXB, após desativar a validação da resposta, o conteúdo do arquivo não estava sendo "desserializado" corretamente.<br />
<br />
Eles criaram uma tag DocZip que armazena um XML compactado com GZIP no formato BASE-64 e declararam o conteúdo da tag como se tivesse um documento XML. É óbvio que algo em BASE-64 não é um XML válido.<br />
<br />
Como o governo incompetente não testa o que faz, tive que corrigir o schema e estou disponibilizando para que outros também não percam tempo. Mesmo sem saber escrever schemas XML, cheguei <a href="http://stackoverflow.com/questions/376582/xml-schema-element-with-attributes-containing-only-text" target="_blank">nessa dúvida</a> que me ajudou a fazer a correção.<br />
<br />
<a href="http://pastebin.com/bNRspBSd" target="_blank">Link para o arquivo retDistDFeInt_v1.00.xsd corrigido</a><br />
<br />
<a href="http://pastebin.com/8c1RSCKZ" target="_blank">Link para o diff/patch contra o arquivo XSD original</a><br />
<br />
Edit:<br />
<br />
Se tem uma coisa pior que incompetência que acontece com muita frequência na Receita Federal do PT ultimamente é a sacanagem. Após escrever esse artigo, mandei a mesma informação através do Fale Conosco, e antes mesmo de obter resposta (geralmente é um robô que responde algo sem sentido), desconfiei de uma coisa e fui verificar.<br />
<br />
A Receita Federal, na tentativa de esconder seus erros, costuma lançar correções de arquivos e disponibilizá-los com o mesmo número de versão. E não é que aconteceu exatamente isso agora?<br />
<br />
Tenho o arquivo PL_NFeDistDFe_100.zip com data de 07/01/2015 que tinha o problema. O arquivo presente <a href="http://www.nfe.fazenda.gov.br/portal/listaConteudo.aspx?tipoConteudo=/fwLvLUSmU8=" target="_blank">nesta página</a> nesse momento tem o mesmo nome e diz que foi atualizado em 19/09/2014, porém ele já está corrigido!Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-21249041234845723152014-12-01T22:12:00.000-02:002014-12-01T22:12:10.938-02:00Artigo "Novidades do Firebird 2.5": Linguagem PSQL<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<div style="text-align: left;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">A linguagem procedural do Firebird, a PSQL, foi incrementada com novos comandos e outras melhorias. A primeira melhoria que irei apresentar se trata do uso de subqueries como expressões PSQL. Antes, o desenvolvedor era obrigado a criar uma variável e fazer um SELECT INTO para obter um valor e usá-lo posteriormente em outro comando. Agora as subqueries fazem parte do conjunto de expressões PSQL e podem ser usadas da mesma maneira que já podiam ser usadas em comandos SQL. A </span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">listagem 15</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> mostra o uso de uma subquery em uma comparação e em seguida na atribuição de um valor retornado a uma variável.</span></div>
</div>
<b id="docs-internal-guid-174cc87a-084d-ef7a-f22c-c1bd28172299" style="font-weight: normal;"><br /></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Listagem 15</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Usando subqueries como expressões PSQL.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SET TERM !;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">EXECUTE BLOCK RETURNS (COD VARCHAR(10)) AS</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">BEGIN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> IF ((SELECT COUNT(*) FROM DOCUMENTOS) > 3) THEN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> BEGIN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> COD = (SELECT MAX(CODIGO) FROM DOCUMENTOS);</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> SUSPEND;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> END</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">END!</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SET TERM ;!</span></div>
<b style="font-weight: normal;"><br /></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<div style="text-align: left;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Na </span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">listagem 15</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> o parâmetro de retorno COD foi definido com o tipo VARCHAR(10) e recebe um valor lido da coluna CODIGO da tabela DOCUMENTOS. Uma alteração do tipo desta coluna poderia deixar este bloco de código inconsistente ou inválido. No Firebird 2.1 foi adicionado o suporte ao uso de domains em PSQL. Neste caso, o desenvolvedor precisaria criar um domínio e usá-lo na definição da tabela e na definição do parâmetro de retorno do EXECUTE BLOCK para ter um código consistente. Dependendo da situação, a criação de domínios para todas as colunas pode se tornar uma tarefa extremamente burocrática. Pensando nisso, o Firebird 2.5 adiciona a cláusula TYPE OF COLUMN. Com essa cláusula é possível declarar parâmetros e variáveis ou fazer casts usando o tipo definido de uma coluna. Ao alterar o tipo da coluna, a alteração se reflete automaticamente em todas as stored procedures e triggers que façam uso de seu tipo. A </span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">listagem 16</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> mostra o mesmo código da </span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">listagem 15</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> mas usando TYPE OF COLUMN para o parâmetro COD.</span></div>
</div>
<b style="font-weight: normal;"><br /></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Listagem 16</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Usando a cláusula TYPE OF COLUMN.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">EXECUTE BLOCK RETURNS (COD TYPE OF COLUMN DOCUMENTOS.CODIGO) AS</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">BEGIN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> IF ((SELECT COUNT(*) FROM DOCUMENTOS) > 3) THEN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> BEGIN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> COD = (SELECT MAX(CODIGO) FROM DOCUMENTOS);</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> SUSPEND;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> END</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">END!</span></div>
<b style="font-weight: normal;"><br /></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<div style="text-align: left;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">No Firebird 2.1 foram acrescentados os triggers de eventos de banco de dados, como o evento ON CONNECT. Uma das funcionalidades que podiam ser feitas com este tipo de trigger era a rejeição de uma conexão, permitindo que os desenvolvedores implementassem um sistema de segurança dentro do banco de dados. Para rejeitar uma conexão é necessário lançar uma exceção dentro do trigger. Nota: este tipo de segurança não impede que o usuário SYSDBA tenha acesso ao banco, pois os administradores podem desativar os triggers de banco de dados conectando-se usando a opção -nodbtriggers do ISQL. O problema é que alguns desenvolvedores gostariam de gravar uma entrada em uma tabela de log registrando o evento, mas a exceção causava o rollback da criação deste registro. Esta e outras situações (como comunicação com outros sistemas através de UDFs) agora podem se beneficiar de um novo comando, o IN AUTONOMOUS TRANSACTION. Assim como um IF ou WHILE, este comando aceita um subcomando (ou vários, com o uso de BEGIN END). No início da execução do IN AUTONOMOUS TRANSACTION é aberta uma nova transação e o subcomando é executado dentro desta transação. Caso o subcomando execute por completo, é feito um COMMIT na transação criada. Caso ocorra uma exceção, é feito um rollback. A </span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">listagem 17</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> apresenta um trigger ON CONNECT que aceita apenas conexões dos usuários SYSDBA e ADMIN e grava o nome dos outros usuários que tiverem a conexão rejeitada. Note que a exceção usada para rejeitar a conexão é lançada fora do bloco IN AUTONOMOUS TRANSACTION, que já havia terminado e, consequentemente, inserido o registro e finalizado a transação com COMMIT.</span></div>
</div>
<b style="font-weight: normal;"><br /></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Listagem 17</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Usando o comando IN AUTONOMOUS TRANSACTION.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">CREATE TABLE CONN_LOG (USUARIO VARCHAR(128), DATA TIMESTAMP);</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">CREATE EXCEPTION E_CONN 'Acesso negado.';</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SET TERM !;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">CREATE TRIGGER T_CONN ON CONNECT AS</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">BEGIN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> IF (CURRENT_USER <> 'SYSDBA' AND CURRENT_USER <> 'ADMIN') THEN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> BEGIN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> IN AUTONOMOUS TRANSACTION DO</span><br />
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> BEGIN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> INSERT INTO CONN_LOG</span><br />
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> VALUES (CURRENT_USER, CURRENT_TIMESTAMP);</span><br />
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> END</span><br />
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> EXCEPTION E_CONN;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> END</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">END!</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SET TERM ;!</span></div>
<b style="font-weight: normal;"><br /></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<div style="text-align: left;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">O comando EXECUTE STATEMENT ganha algumas novidades importantes na versão 2.5. Uma delas é uma das funcionalidades mais pedidas pelos usuários: ler e atualizar dados em outros bancos de dados. Através da cláusula ON EXTERNAL DATA SOURCE é possível especificar o banco de dados em que o comando executará. É permitido também que o desenvolvedor especifique o nome, senha e role do usuário para fazer a conexão, e o funcionamento da transação iniciada para rodar o comando no banco de dados externo. Com WITH COMMON TRANSACTION (opção default), a transação da conexão externa é agrupada à transação interna atual e o comando COMMIT ou ROLLBACK executado na transação atual é propagado às transações externas. Com WITH AUTONOMOUS TRANSACTION o funcionamento se torna similar as transações autônomas, sendo feito o COMMIT ou ROLLBACK logo após a execução sucedida ou não do comando externo. A </span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">listagem 18</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> mostra o uso deste comando para ler e gravar dados em outro banco de dados.</span></div>
</div>
<b style="font-weight: normal;"><br /></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Listagem 18</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Executando comandos em outros bancos de dados com EXECUTE STATEMENT.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SET TERM !;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">EXECUTE BLOCK RETURNS (NOME VARCHAR(60)) AS</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> DECLARE BANCO VARCHAR(60) = 'localhost:/db/pessoas.fdb';</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> DECLARE USUARIO VARCHAR(10) = 'SYSDBA';</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> DECLARE SENHA VARCHAR(10) = 'masterke';</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> DECLARE NOME_INSERIR VARCHAR(20) = 'Sicrano';</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">BEGIN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> FOR EXECUTE STATEMENT 'SELECT NOME FROM PESSOAS'</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> ON EXTERNAL DATA SOURCE BANCO</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> AS USER USUARIO PASSWORD SENHA</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> INTO NOME</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> DO</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> BEGIN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> SUSPEND;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> END</span></div>
<b style="font-weight: normal;"><br /></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> EXECUTE STATEMENT</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> 'INSERT INTO PESSOAS (NOME) VALUES (''' || NOME_INSERIR || ''')'</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> ON EXTERNAL DATA SOURCE BANCO</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> AS USER USUARIO PASSWORD SENHA</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> WITH AUTONOMOUS TRANSACTION;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">END!</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SET TERM ;!</span></div>
<b style="font-weight: normal;"><br /></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<div style="text-align: left;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">A </span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">listagem 18</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> mostra como era feita a criação de strings de SQL dinâmico, usando concatenação de strings. A criação de comandos com concatenação é insegura, pois um usuário mal-intencionado pode gerar comandos não previstos pelo desenvolvedor, causando o ataque conhecido como injeção de SQL [1]. No novo EXECUTE STATEMENT é possível passar parâmetros de duas formas diferentes. A </span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">listagem 19</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> mostra o uso de parâmetros anônimos, com o símbolo de interrogação.</span></div>
</div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; text-indent: 36pt;">
<div style="text-align: left;">
<br /></div>
</div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Listagem 19</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Usando EXECUTE STATEMENT com parâmetros anônimos.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SET TERM !;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">EXECUTE BLOCK AS</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> DECLARE NOME VARCHAR(20) = 'Sicrano';</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> DECLARE DATA_NASCIMENTO DATE = DATE '2000-01-01';</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">BEGIN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> EXECUTE STATEMENT</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> ('INSERT INTO PESSOAS (NOME, DATA_NASCIMENTO) VALUES (?, ?)')</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> (NOME, DATA_NASCIMENTO);</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">END!</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SET TERM ;!</span></div>
<b style="font-weight: normal;"><br /></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<div style="text-align: left;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Além da passagem de parâmetros anônimos, o comando EXECUTE STATEMENT agora suporta o uso de parâmetros nomeados. As vantagens dos parâmetros nomeados são que o desenvolvedor não precisa se preocupar com a ordem e também pode usar um mesmo parâmetro mais de uma vez sem a necessidade de criação de variáveis. O uso dos parâmetros dentro da string é similar a passagem de parâmetros feita com o símbolo dois-pontos em bibliotecas Delphi, como expliquei na parte referente à construção “? IS NULL”. Os valores são associados aos nomes dos parâmetros usando-se o operador “:=” (dois pontos, igual). A </span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">listagem 20</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> mostra o uso de parâmetros nomeados.</span></div>
</div>
<b style="font-weight: normal;"><br /></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Listagem 20</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Usando EXECUTE STATEMENT com parâmetros nomeados.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SET TERM !;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">EXECUTE BLOCK AS</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> DECLARE NOME VARCHAR(20) = 'Sicrano';</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> DECLARE DATA_NASCIMENTO DATE = DATE '2000-01-01';</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">BEGIN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> EXECUTE STATEMENT</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> ('INSERT INTO PESSOAS (NOME, DATA_NASCIMENTO)</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> VALUES (:P_NOME, :P_DATA_NASCIMENTO)')</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> (P_DATA_NASCIMENTO := DATA_NASCIMENTO, P_NOME := NOME);</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">END!</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SET TERM ;!</span></div>
<br />
<div dir="ltr" style="margin-bottom: 0pt; margin-top: 0pt; text-align: start; text-indent: 0px;">
<span style="vertical-align: baseline;"><b>N</b></span><span style="font-size: 13px; font-weight: bold; line-height: 1.15; vertical-align: baseline; white-space: pre-wrap;">ota</span><br />
<span style="font-size: 13px; line-height: 1.15; text-align: justify; text-indent: 36pt; white-space: pre-wrap;"><br /></span>
<div style="text-align: left;">
<span style="font-size: 13px; line-height: 1.15; text-align: justify; text-indent: 36pt; white-space: pre-wrap;">[1] Injeção de SQL é o nome de um ataque em que o usuário mal-intencionado preenche dados de um formulário de forma que um comando gerado no servidor através de concatenação de strings seja alterado. Geralmente o ataque é feito usando-se aspas simples e um restante de código que termine o comando iniciado pelo desenvolvedor, seguindo com outro comando completo e o símbolo de início de comentário (--) para invalidar o restante do comando.</span></div>
</div>
<div>
<div style="text-align: left;">
<span style="font-size: 13px; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div>
</div>
Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-33858726981654692642014-11-18T23:25:00.001-02:002014-11-18T23:26:01.012-02:00C++: Argument-dependent name lookupSometimes C++ still surprises me. Consider this code:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">namespace ns1</span><br />
<span style="font-family: Courier New, Courier, monospace;">{</span><br />
<span style="font-family: Courier New, Courier, monospace;"><span style="white-space: pre;"> </span>class C1</span><br />
<span style="font-family: 'Courier New', Courier, monospace; white-space: pre;"> </span><span style="font-family: Courier New, Courier, monospace;">{</span><br />
<span style="font-family: 'Courier New', Courier, monospace; white-space: pre;"> </span><span style="font-family: Courier New, Courier, monospace;">};</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: 'Courier New', Courier, monospace; white-space: pre;"> </span><span style="font-family: Courier New, Courier, monospace;">void f1(const C1&)</span><br />
<span style="font-family: 'Courier New', Courier, monospace; white-space: pre;"> </span><span style="font-family: Courier New, Courier, monospace;">{</span><br />
<span style="font-family: 'Courier New', Courier, monospace; white-space: pre;"> </span><span style="font-family: Courier New, Courier, monospace;">}</span><br />
<span style="font-family: Courier New, Courier, monospace;">}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">int main()</span><br />
<span style="font-family: Courier New, Courier, monospace;">{</span><br />
<span style="font-family: 'Courier New', Courier, monospace; white-space: pre;"> </span><span style="font-family: Courier New, Courier, monospace;">ns1::C1 c1;</span><br />
<span style="font-family: 'Courier New', Courier, monospace; white-space: pre;"> </span><span style="font-family: Courier New, Courier, monospace;">f1(c1);</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span><span style="font-family: 'Courier New', Courier, monospace; white-space: pre;"> </span><span style="font-family: Courier New, Courier, monospace;">return 0;</span><br />
<span style="font-family: Courier New, Courier, monospace;">}</span><br />
<br />
If you think it's wrong and causes a compiler error, you're wrong.<br />
<br />
The function "f1" is not in the scope of "main", but its argument has a type of the same namespace, causing the function to be located.<br />
<br />
This rule is called <a href="http://en.wikipedia.org/wiki/Argument-dependent_name_lookup" target="_blank">Argument-dependent name lookup (or Koenig lookup)</a> and it is also very necessary in relation to operators.Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-34249214673156474912014-03-31T21:47:00.000-03:002014-03-31T22:02:20.141-03:00Artigo "Novidades do Firebird 2.5": Expressões, literais e funçõesNa parte de expressões SQL, o Firebird 2.5 acrescenta melhorias e novidades. A função agregada LIST (presente desde a versão 2.1) agora aceita qualquer expressão em seu segundo parâmetro, onde o desenvolvedor pode especificar a string de separação dos elementos retornados. Até a versão 2.1.3 era possível apenas o uso de strings constantes nesse parâmetro. Nota: a versão 2.1.4 também deve ser liberada com esta novidade. A <b>listagem 10</b> mostra a utilidade deste parâmetro, principalmente no desenvolvimento de relatórios, agrupando várias mensagens referentes a um documento em um mesmo registro e mostrando cada mensagem em uma linha.<br />
<br />
<b>Listagem 10</b>. Usando a função LIST com expressões no segundo parâmetro.<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SELECT LIST(MENSAGEM, ASCII_CHAR(13) || ASCII_CHAR(10))</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> FROM MENSAGENS_DOCUMENTO WHERE DOCUMENTO = 10;</span></div>
<b style="font-weight: normal;"><br /><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b>
Referente a parâmetros de comandos SQL, o Firebird suporta apenas o uso de parâmetros anônimos com o símbolo “?” (ponto de interrogação). Algumas bibliotecas (inclusive de Delphi) aceitam o uso de parâmetros nomeados usando “:” (dois pontos). Quando o desenvolvedor tentava escrever queries usando o padrão [WHERE :CODIGO IS NULL OR CODIGO = :CODIGO] para trazer todos os registros quando o parâmetro não fosse informado, o Firebird retornava um erro. Isto porque este comando é traduzido pelas bibliotecas para [WHERE ? IS NULL OR CODIGO = ?] e o Firebird não aceitava o uso de parâmetro com o predicado IS NULL, pois o tipo do parâmetro era considerado como desconhecido. Na versão 2.5 foi adicionado à API o tipo SQL_NULL. As bibliotecas de acesso precisam entender este novo tipo e apenas passar se o valor do parâmetro é ou não NULL, permitindo assim o uso deste padrão de comando.<br />
<br />
Outra novidade referente a expressões é o novo predicado SIMILAR TO. Esta expressão é usada para fazer comparações usando expressões regulares de acordo com o padrão SQL. A <b>listagem 11</b> mostra uma verificação de números de telefones cadastrados fora do padrão (NN) NNNN-NNNN. O caractere de escape funciona exatamente como no comando LIKE, considerando o próximo caractere como um valor literal, ao invés de usá-lo como um operador.<br />
<br />
<b>Listagem 11.</b> Verificando números de telefones cadastrados fora do padrão.<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SELECT * FROM PESSOAS</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> WHERE TELEFONE NOT SIMILAR TO</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> '\([0-9]{2}\) [0-9]{4}\-[0-9]{4}' escape '\'</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div>
A <b>tabela 1</b> mostra os operadores permitidos em expressões regulares e a <b>tabela 2</b> mostra as classes de caracteres que podem ser usadas com o operador [[:CLASSE:]].<br />
<br />
<span style="vertical-align: baseline;"></span><br />
<div dir="ltr" style="margin-left: 0pt;">
<table style="border-collapse: collapse; border: none;"><colgroup><col width="108"></col><col width="516"></col></colgroup><tbody>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Operador</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Descrição</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">X{2}</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Duas ocorrências de X.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">X{2,}</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Duas ou mais ocorrências de X.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">X{4,6}</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">De quatro a seis ocorrências de X.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">X?</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Zero ou uma ocorrência de X.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">X*</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Zero ou mais ocorrências de X.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">X+</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Uma ou mais ocorrências de X.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">X|Y</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">X ou Y.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">_</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Qualquer caractere - como no LIKE.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">%</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Qualquer sequência de caracteres - como no LIKE.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">(X)</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Agrupa X para ser tratado pelo operador subsequente.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[XYZ]</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Qualquer caractere igual a X, Y ou Z.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[^XYZ]</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Qualquer caractere diferente de X, Y ou Z.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[X-Z]</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Qualquer caractere entre X e Z.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">[[:CLASSE:]]</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Qualquer caractere de uma certa classe, conforme </span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">tabela 2</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">.</span></div>
</td></tr>
</tbody></table>
</div>
<div dir="ltr" style="margin-left: 0pt;">
<b>Tabela 1.</b> Operadores de expressões regulares.<br />
<br />
<br />
<table style="border-collapse: collapse; border: none;"><colgroup><col width="108"></col><col width="516"></col></colgroup><tbody>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Classe</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Descrição</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ALPHA</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Qualquer caractere entre A e Z.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">UPPER</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Qualquer caractere maiúsculo.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">LOWER</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Qualquer caractere minúsculo.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">DIGIT</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Dígitos de 0 a 9.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SPACE</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Espaço: caractere (ASCII_CHAR) 32.</span></div>
</td></tr>
<tr style="height: 0px;"><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">WHITESPACE</span></div>
</td><td style="border: 1px solid #000000; padding: 7px 7px 7px 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Todo tipo de espaço: caracteres 9, 10, 11, 12, 13 e 32.</span></div>
</td></tr>
</tbody></table>
</div>
<b>Tabela 2.</b> Classes de caracteres para expressões regulares.<b style="font-weight: normal;"><br /><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b>
<b style="font-weight: normal;"><br /></b>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
</div>
O Firebird 2.5 também suporta novos formatos de valores literais (constantes) para números e strings. Agora é possível escrever números inteiros no formato hexadecimal, usando o prefixo 0x. Quando o número possuir até 8 dígitos hexadecimais após o 0x, como em 0xFFFFFFFF, o número adquire o tipo INTEGER (32 bits com sinal). Quando possuir mais de 8 dígitos, como em 0x0FFFFFFFF, o tipo adquirido é o BIGINT (64 bits com sinal). Desta forma, estas duas constantes retornam valores diferentes, pois os números negativos são armazenados na notação complemento de dois [1].<br />
<br />
Além de números, também é possível a criação de strings binárias (character set OCTETS) usando a notação hexadecimal x''. Em ambos os casos a letra X pode ser escrita em maiúscula ou minúscula. A listagem 12 mostra o uso destes novos tipos de valores literais. Note que cada par de caracteres hexadecimais se transforma em um byte na string resultante.<br />
<div>
<br />
<b>Listagem 12.</b> Novos formatos de expressões literais.<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SELECT 0xDEADBEEF, x'DEADBEEF' FROM RDB$DATABASE;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SELECT OCTET_LENGTH(x'DEADBEEF') FROM RDB$DATABASE;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">-- Resultado de OCTET_LENGTH: 4, e não 8</span></div>
<b style="font-weight: normal;"><br /><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b>
A nova função BIN_NOT se junta ao grupo de funções binárias adicionadas na versão 2.1, BIN_AND e BIN_OR. Junto com as constantes hexadecimais, essa família de funções facilita o uso de máscaras de valores binários gravados em um único campo, técnica comumente utilizada em aplicações e agora facilitada no banco de dados. A <b>listagem 13 </b>mostra o uso da função BIN_NOT, que inverte todos os bits de um valor inteiro.<br />
<br />
<b>Listagem 13.</b> Exemplo de uso da função BIN_NOT.<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space: pre;"> </span>SELECT BIN_NOT(0xFFFFFFFF) FROM RDB$DATABASE; -– Resultado: 0</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></div>
<div dir="ltr" style="margin-bottom: 0pt; margin-top: 0pt;">
<span style="text-indent: 36pt; vertical-align: baseline;"><span style="font-size: x-small;"><span style="line-height: 1.15; white-space: pre-wrap;"><br /></span></span></span></div>
Na versão 2.1 foi adicionada a função GEN_UUID, que retorna um UUID [2] como um valor do tipo CHAR(16) CHARACTER SET OCTETS. Este tipo de retorno foi escolhido pois é a representação mais compacta para ser usado em índices, porém requer suporte das aplicações que desejam exibir estes UUIDs aos usuários. Na nova versão foram adicionadas funções para conversão entre as representações binária e texto [CHAR(36) CHARACTER SET ASCII] de UUIDs, as funções CHAR_TO_UUID e UUID_TO_CHAR. O formato texto de UUID aceito e retornado por estas funções é 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'. A <b>listagem 14</b> mostra o uso destas funções.<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify; text-indent: 36pt;">
<br /></div>
<b style="font-weight: normal;"><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b><br />
<b>Listagem 14.</b> Exemplo de uso das funções UUID_TO_CHAR e CHAR_TO_UUID.<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SELECT UUID_TO_CHAR(UUID), DESCRICAO FROM OBJETOS</span></div>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> WHERE UUID = CHAR_TO_UUID(?);</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></div>
<div>
<br /></div>
<br />
<b>Notas</b><br />
<br />
[1] - Complemento de dois é a notação mais comum usada para representar números inteiros com sinal em sistemas computacionais. Nesta notação o bit mais significativo de um número positivo ou do número zero é representado como 0. Os números negativos são representados com os bits invertidos e somado o valor 1. Desta forma, em um número de 32 bits o 1 é representado com trinta e um bits 0 seguido por um bit 1, enquanto que o número -1 é representado por trinta e dois bits 1.<br />
<br />
[2] - UUID (Universally Unique Identifier) é uma sequência aleatória de 16 bytes que, independente do local e momento que seja gerada, é única. Uma das utilidades dos UUIDs é criar chaves em sistemas distribuídos, como filiais de uma empresa com bancos de dados separados e que tenham os dados agregados em um banco principal através de replicação.</div>
Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-8674499679612893352014-01-12T21:52:00.001-02:002014-01-12T21:52:25.083-02:00Artigo "Novidades do Firebird 2.5": Comandos DDLAlém do comando CREATE COLLATION, mostrado na seção anterior, o Firebird 2.5 acrescenta comandos DDL que aliviam limitações anteriores e outros comandos totalmente novos. Duas limitações existentes nas versões anteriores eram relacionadas à impossibilidade de alteração de colunas COMPUTED BY e views. Era preciso eliminar estes objetos e recriá-los com as alterações. O problema é que o Firebird não permite que um objeto seja eliminado quando este está sendo usado por outro objeto. Algumas ferramentas (como o Flamerobin, por exemplo) geram scripts para eliminar e recriar objetos durante a alteração de um objeto que não era permitida, porém esta não é a solução ideal.<b style="font-weight: normal;"><br /><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b>
<div dir="ltr" style="margin-bottom: 0pt; margin-top: 0pt;">
<span style="vertical-align: baseline;"> <span style="font-size: x-small;"><span style="line-height: 1.15; white-space: pre-wrap;">A </span></span></span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; line-height: 1.15; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">listagem 5</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1.15; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> mostra o comando usado para alteração de uma expressão COMPUTED no Firebird 2.5 e a </span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; line-height: 1.15; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">listagem 6</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; line-height: 1.15; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> mostra um exemplo do comando ALTER VIEW.</span></div>
<b style="font-weight: normal;"><br /><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Listagem 5</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Exemplo de alteração de expressão COMPUTED BY.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">-- Criação da tabela com erro na expressão da coluna IDADE.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">CREATE TABLE PESSOAS (</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> NOME VARCHAR(60),</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> DATA_NASCIMENTO DATE,</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> IDADE COMPUTED BY (DATEDIFF(YEAR, CURRENT_DATE, DATA_NASCIMENTO)));</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">INSERT INTO PESSOAS VALUES ('Fulano', '2000-01-01');</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">INSERT INTO PESSOAS VALUES ('Beltrano', '1950-05-10');</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SELECT * FROM PESSOAS; -- Lista a idade como negativa.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">-- Correção da expressão da coluna IDADE.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ALTER TABLE PESSOAS</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> ALTER IDADE COMPUTED BY (DATEDIFF(YEAR, DATA_NASCIMENTO, CURRENT_DATE));</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SELECT * FROM PESSOAS;</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></div>
<b style="font-weight: normal;"><br /><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Listagem 6</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Exemplo do comando ALTER VIEW.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">-- View criada incorretamente sem a expressão WHERE.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">CREATE VIEW PESSOAS_MAIORES AS</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> SELECT * FROM PESSOAS;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">-- Correção da view.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ALTER VIEW PESSOAS_MAIORES AS</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> SELECT * FROM PESSOAS WHERE IDADE >= 18;</span></div>
<b style="font-weight: normal;"><br /><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b>
Assim como em outros comandos DDL, também é permitido o uso dos comandos RECREATE VIEW e CREATE OR ALTER VIEW. Além dos novos comandos relacionados a views, agora é permitido o uso de stored procedures na cláusula FROM de uma view, o que não era permitido nas versões anteriores. A <b>listagem 7</b> mostra um exemplo.<div>
<br /><div>
<b style="font-weight: normal;"><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b><br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Listagem 7</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Exemplo de uso de stored procedure em uma view.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SET TERM !;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">CREATE PROCEDURE PESSOAS_SP RETURNS (NOME VARCHAR(60), IDADE INTEGER) AS</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">BEGIN</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> FOR SELECT NOME, IDADE FROM PESSOAS INTO NOME, IDADE DO</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> SUSPEND;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">END!</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">SET TERM ;!</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">CREATE VIEW PESSOAS_SP_MAIORES AS</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> SELECT * FROM PESSOAS_SP WHERE IDADE >= 18;</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></div>
<b style="font-weight: normal;"><br /><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b>
Na nova versão também foram incluídos comandos DDL para manuseio do banco de dados de usuários. Estes comandos são: CREATE USER, ALTER USER e DROP USER. Estes comandos podem ser executados quando conectado a qualquer banco de dados, mas sempre atualizam os dados do banco de dados geral de usuários (security2.fdb). Os comandos CREATE USER e DROP USER podem ser usados apenas por usuários com privilégio de administrador. O comando ALTER USER pode ser usado por qualquer usuário, desde que usado para alterar apenas suas próprias informações (a senha, por exemplo). Já os administradores podem usar ALTER USER para alterar informações de qualquer usuário. Além da senha (PASSWORD), é possível registrar os nomes (FIRSTNAME, MIDDLENAME e LASTNAME) e definir se um usuário é ou não um administrador com a cláusula GRANT/REVOKE ADMIN ROLE. A <b>listagem 8</b> mostra exemplos de criação, alteração e remoção de usuários.</div>
<div>
<br /><b style="font-weight: normal;"><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b><br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Listagem 8</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Manuseio do banco de dados de segurança com comandos SQL.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">CREATE USER FULANO PASSWORD 'altereja'</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> FIRSTNAME 'Fulano' LASTNAME 'da Silva';</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ALTER USER SYSDBA PASSWORD 'masterkey';</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">DROP USER BELTRANO;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">CREATE USER ADMIN_ADJUNTO PASSWORD 'masterkey' GRANT ADMIN ROLE;</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">GRANT RDB$ADMIN TO ADMIN_ADJUNTO;</span></div>
<b style="font-weight: normal;"><br /><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b>
Para um usuário tornar-se efetivamente um administrador, um usuário que já seja administrador (como o SYSDBA) precisa, além de colocar GRANT ADMIN ROLE no CREATE USER ou ALTER USER, conceder a role RDB$ADMIN ao usuário com o comando “GRANT RDB$ADMIN TO Usuario” em cada banco de dados que o usuário poderá atuar como administrador. O usuário também precisará conectar-se ao banco de dados usando a ROLE RDB$ADMIN. A <b>listagem 9</b> mostra o usuário ADMIN_ADJUNTO atuando como SYSDBA.</div>
<div>
<br /><b style="font-weight: normal;"><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"></span></b><br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: bold; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Listagem 9</span><span style="background-color: transparent; color: black; font-family: Tahoma; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">. Conectando-se com privilégios de administrador a um banco de dados.</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">CONNECT 'TEST.FDB' USER ADMIN_ADJUNTO</span></div>
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"> PASSWORD 'masterkey' ROLE RDB$ADMIN;</span></div>
<br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-left: 36pt; margin-top: 0pt; text-align: justify;">
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">DROP USER FULANO;</span></div>
<div>
<span style="background-color: transparent; color: black; font-family: 'Courier New'; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div>
</div>
</div>
Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-62120765861776248812014-01-05T21:00:00.000-02:002014-01-05T21:00:03.506-02:00Artigo "Novidades do Firebird 2.5": Character Sets e CollatesNo Firebird, diferentes tabelas ou até mesmo diferentes colunas de uma mesma tabela podem usar diferentes character sets e collates. Isto permite uma grande flexibilidade mas pode causar problemas caso o desenvolvedor ou DBA não se atente às necessidades da aplicação. Por isso, um banco de dados pode ter um character set default, que é automaticamente usado quando não é especificado um character set durante a definição de uma coluna de tipo string. Algo semelhante não existia para collates, sendo que o collate default de cada character set é o modo de comparação binária dos bytes que compõem uma string.<br /><br /> Na nova versão foi introduzido o comando ALTER CHARACTER SET, permitindo a alteração do collate padrão de um character set. Além do comando ALTER CHARACTER SET, agora o collate padrão do character set padrão do banco pode ser definido no momento da criação do banco de dados. A <b>listagem 1</b> mostra a criação de um banco de dados usando o character set padrão WIN1252 e definindo seu collate padrão para WIN_PTBR. Em seguida o collate padrão do character set UTF8 é alterado para UNICODE_CI_AI.<br /><br /><span style="vertical-align: baseline;"></span><br />
<b>Listagem 1</b>. Exemplos de alteração de collate padrão.<br /><br /><div>
<div>
<span style="font-family: Courier New, Courier, monospace;">CREATE DATABASE 'TEST.FDB'<br /> DEFAULT CHARACTER SET WIN1252<br /> COLLATION WIN_PTBR;<br /><br />ALTER CHARACTER SET UTF8<br /> SET DEFAULT COLLATION UNICODE_CI_AI;</span><br /><br /><span style="vertical-align: baseline;"></span><br />
A <b>listagem 2</b> mostra o banco operando com o character set default WIN1252 e o collate WIN_PTBR (case-insensitive).<br /><br /><b>Listagem 2</b>. Comparação de strings usando o collate WIN_PTBR.<br /><br /><span style="font-family: Courier New, Courier, monospace;">CREATE TABLE PESSOAS (NOME VARCHAR(20));<br /><br />INSERT INTO PESSOAS VALUES ('Fulano');<br />INSERT INTO PESSOAS VALUES ('Beltrano');<br /><br />-- Localiza Fulano (= FULANO)<br />SELECT * FROM PESSOAS WHERE NOME = 'FULANO';</span><br /><br /> Outra necessidade comumente encontrada em aplicações é a gravação de códigos alfanuméricos. Até o Firebird 2.1 a ordenação de campos do tipo string era sempre feita no modo de comparação de texto. Isto quer dizer que um código “A10” é listado antes de “A2” caso ordenado por esta coluna. A <b>listagem 3</b> mostra um exemplo desta situação.<br /><br /><b>Listagem 3</b>. Ordenação de códigos alfanuméricos usando o collate UNICODE.<br /><span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<span style="font-family: Courier New, Courier, monospace;">CREATE TABLE DOCUMENTOS (<br /> CODIGO VARCHAR(10) CHARACTER SET UTF8 COLLATE UNICODE<br />);<br /><br />INSERT INTO DOCUMENTOS VALUES ('A1');</span><div>
<span style="font-family: Courier New, Courier, monospace;">INSERT INTO DOCUMENTOS VALUES ('A2');<br />INSERT INTO DOCUMENTOS VALUES ('A10');<br />INSERT INTO DOCUMENTOS VALUES ('A11');<br />INSERT INTO DOCUMENTOS VALUES ('A100');<br />INSERT INTO DOCUMENTOS VALUES ('B1');<br />INSERT INTO DOCUMENTOS VALUES ('B10');<br /><br />-- Resultado: A1, A10, A100, A11, A2, B1, B10<br />SELECT CODIGO FROM DOCUMENTOS ORDER BY CODIGO;</span><br /><br /><br /> O Firebird 2.5 permite que collates sejam configuráveis, e uma das opções do collate UNICODE permite que números sejam ordenados por ordem numérica. A <b>listagem 4</b> mostra a criação do collate UNICODE_NUM com o uso da opção NUMERIC-SORT e a ordenação usando este collate.</div>
<div>
<br /><b>Listagem 4</b>. Ordenação usando a opção NUMERIC-SORT do collate UNICODE.<br /><div>
<br /><span style="font-family: Courier New, Courier, monospace;">CREATE COLLATION UNICODE_NUM FOR UTF8 FROM UNICODE 'NUMERIC-SORT=1';<br /><br />CREATE TABLE DOCUMENTOS2 (<br /> CODIGO VARCHAR(10) CHARACTER SET UTF8 COLLATE UNICODE_NUM<br />);<br /><br />INSERT INTO DOCUMENTOS2 SELECT * FROM DOCUMENTOS;<br /><br />-- Resultado: A1, A2, A10, A11, A100, B1, B10<br />SELECT CODIGO FROM DOCUMENTOS2 ORDER BY CODIGO;</span><br /><br /><br /> Outra novidade da versão 2.5 é o collate UNICODE_CI_AI (para o character set UTF8), variação do collate UNICODE pré-configurado para desconsiderar diferenças de acentos e maiúsculas/minúsculas. O collate UNICODE_CI_AI funciona de maneira similar ao WIN_PTBR e PT_BR, mas aceita o conjunto completo de caracteres Unicode.</div>
</div>
</div>
Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-15219906850320044392014-01-02T11:34:00.000-02:002014-01-02T11:34:55.297-02:00Artigo "Novidades do Firebird 2.5": A arquitetura SuperClassicDesde sua primeira versão, o Firebird foi disponibilizado em dois modos de operação (chamados de arquiteturas) diferentes, a SuperServer e a Classic. Na SuperServer as conexões aos bancos de dados são gerenciadas com múltiplas threads em um único processo do SO, enquanto que na Classic é aberto um processo para cada conexão realizada.<br />
<br />
A vantagem da arquitetura SuperServer é que diversas conexões a um mesmo banco de dados são gerenciadas com apenas um cache de dados e metadados. Sua desvantagem é que, internamente, a execução de queries é feita de maneira cooperativa, isto é, em determinados pontos uma query paralisa sua própria execução e passa o controle para que outra query continue executando, não aproveitando adequadamente os recursos de máquinas com mais de um processador ou núcleo. Nota: O time de desenvolvedores do Firebird trabalha para remover completamente esta limitação na versão 3, e a SuperClassic é o primeiro passo em busca desse objetivo. Outra desvantagem da SuperServer é que apenas um processo pode abrir cada banco de dados. Isto causava uma limitação em aplicativos que usavam a biblioteca Embedded, como veremos mais adiante.<br />
<br />
Na arquitetura Classic cada processo pode executar queries paralelamente, de forma preemptiva, porém cada um possui seu exclusivo cache. Para manter a integridade, o Firebird precisa realizar comunicação inter-processo através de seu lock manager. Essa comunicação causa uma perda de desempenho em relação à SuperServer. Nesta arquitetura também existia a possibilidade de trabalhar com diversas conexões em apenas um processo, porém com a mesma limitação presente na SuperServer, onde as queries de um mesmo processo rodavam de maneira cooperativa. Além disso, esta possibilidade existia apenas com a versão Embedded para Linux, pois rodando no modo servidor a criação de novos processos era sempre feita automaticamente a cada conexão.<br />
<br />
O novo modo SuperClassic é uma mistura das duas arquiteturas preexistentes. Um processo SuperClassic pode gerenciar diversas conexões usando threads, como no SuperServer. Mas, diferentemente do SuperServer, cada conexão possui seu cache exclusivo, como no Classic. Como o cache não é compartilhado, as queries podem rodar de maneira preemptiva, melhorando o desempenho em máquinas multiprocessadas.<br />
<br />
A arquitetura SuperServer também teve uma melhoria. Até a versão 2.1 as queries eram sincronizadas por servidor, e na versão 2.5 são sincronizadas por banco de dados. Isto significa que um servidor 2.5 gerenciando conexões a vários bancos de dados aproveitará os recursos de hardware de forma mais satisfatória.<br />
<br />
Além de SuperServer e Classic, o Firebird também é disponibilizado como uma biblioteca: a versão Embedded. Até a versão 2.1 a biblioteca Embedded trabalhava no modo SuperServer no ambiente Windows e no modo Classic em outros SOs. Na versão 2.5 a biblioteca Embedded usa o modo SuperClassic em todos os SOs. Como o SuperClassic é o Classic melhorado, tornou-se possível o acesso simultâneo a um banco de dados por diversos aplicativos usando a biblioteca Embedded, removendo esta limitação que existia em ambientes Windows. Nota: o compartilhamento de um banco de dados em vários processos Classic (ou Embedded) é permitido apenas quando todos os processos sejam da mesma arquitetura, 32 ou 64 bits. Com a mudança de arquitetura da versão Embedded, o desenvolvedor precisa verificar se o desempenho de seu aplicativo foi influenciado negativamente, pois a configuração padrão de buffers dos bancos de dados são diferentes nas duas arquiteturas. Esta configuração pode ser ajustada alterando-se o valor do parâmetro DefaultDbCachePages no arquivo firebird.conf ou com o comando gfix -buffers em cada banco de dados.Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-88186953054800339032013-12-22T20:49:00.000-02:002013-12-22T20:49:02.518-02:00Artigo "Novidades do Firebird 2.5": Migrando de versões anterioresConforme citado na <a href="http://asfernandes.blogspot.com.br/2013/12/artigo-novidades-do-firebird-25.html">introdução</a>, a compatibilidade é levada a sério no Firebird. Infelizmente, porém, às vezes é preciso fazer mudanças que causam certas dificuldades de migração. Antes da versão 2.1 o Firebird tinha importantes bugs referentes a implementação de character sets multibyte herdados do InterBase. Um destes character sets é o UNICODE_FSS, que é usado pelas tabelas de sistema RDB$. O Firebird não convertia, do character set cliente para o UNICODE_FSS, nomes, strings e código fonte de objetos durante a execução de comandos DDL e simplesmente gravava os dados, que do ponto de vista do UNICODE_FSS eram inválidos. A partir da versão 2.1 esta conversão passou a ser feita, embora ainda fosse possível a criação de objetos inválidos usando o character set NONE. Para corrigir os objetos gravados de forma incorreta, foi disponibilizado um script que deveria ser rodado após o restore na versão 2.1.<br />
<br />
A partir da versão 2.5 o Firebird passou a recusar dados e metadados inválidos com o character set UNICODE_FSS. Isto significaria que qualquer banco de dados de versões anteriores que tivesse problemas de character set não poderia ser restaurado na nova versão. Diante dessa situação, foram acrescentadas duas opções ao gbak, para serem usadas durante o processo de restauração e corrigir este tipo de problema.<br />
<br />
A opção -FIX_FSS_METADATA seguida do nome de um character set é usada para informar em que character set foram criados os objetos de banco de dados presentes no backup. Durante a restauração os metadados são convertidos deste character set para o UNICODE_FSS e gravados corretamente.<br />
<br />
A outra opção, -FIX_FSS_DATA seguida do nome de um character set, deve ser usada apenas em bancos de dados que tenham tabelas de usuários criadas usando o character set UNICODE_FSS. Esta opção realiza a conversão dos dados da mesma forma que -FIX_FSS_METADATA realiza a conversão dos metadados.<br />
<br />
O uso destas opções só é necessário caso o banco possua metadados e dados com caracteres fora do padrão ASCII, como caracteres acentuados, por exemplo. É recomendado que se tente inicialmente fazer a restauração sem usar estas opções. Se o processo falhar por estes problemas, será mostrada uma mensagem de erro recomendando o uso. Para usar o character set correto nestas opções, o usuário precisa ter um conhecimento mínimo sobre character sets (ou páginas de códigos de caracteres) e dos sistemas operacionais usados pelas aplicações cliente. Por exemplo, aplicações que executavam comandos DDL pelo Windows (configurado para Português/Brasil) devem usar WIN1252. Já no Linux a maioria das distribuições atuais trabalha com UTF-8, que é compatível com UNICODE_FSS e não deveria causar problemas.<br />
<br />
Estas opções podem não resolver os problemas caso o banco de dados tenha dados ou metadados gravados de forma incorreta usando diferentes character sets. Neste caso será necessário corrigir os problemas com o auxílio dos scripts de migração usando a versão 2.1.<br />
<br />
Após a migração do banco de dados, o desenvolvedor precisa se certificar que seus aplicativos conectam-se ao banco usando o client character set correto. O uso do character set NONE (padrão) ou de um character set incorreto podem causar erros de “malformed string” e “transliteration exception”.Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-18283531622256639412013-12-20T00:01:00.000-02:002013-12-20T00:01:07.567-02:00Artigo "Novidades do Firebird 2.5": IntroduçãoO desenvolvimento do SGBD Firebird foi iniciado em Julho do ano 2000 a partir do código fonte da versão beta do InterBase 6.0, disponibilizado pela Inprise (Borland) sob licença open source. Desde então cinco versões foram lançadas pela sua equipe de desenvolvimento, mostrando uma evolução contínua do produto. O foco deste artigo é mostrar as principais funcionalidades para desenvolvedores adicionadas à versão 2.5, lançada em outubro de 2010, no ano em que o projeto faz seu décimo aniversário. Antes de aprofundar nestes temas, gostaria de mostrar um breve histórico da evolução do Firebird nestes dez anos.<br />
<br />
Na versão 1.0 a maior parte do trabalho foi interna, já que o código inicial não tinha documentação e não chegava nem mesmo a compilar. Uma das alterações mais importantes nesta versão foi a correção de um bug de segurança do InterBase, que foi rapidamente identificado quando seu código tornou-se público.<br />
<br />
Na versão 1.5 o código fonte foi convertido de C para C++. Algumas novidades que apareceram nesta versão foram variáveis de contexto como CURRENT_USER e CURRENT_ROLE, funções como COALESCE e NULLIF, expressões CASE, o tipo de dados BIGINT, melhorias em alguns comandos DDL (CREATE OR ALTER, RECREATE), o comando EXECUTE STATEMENT, as cláusulas FIRST e SKIP e suporte a savepoints e locks pessimistas.<br />
<br />
A versão 2.0 introduziu as tabelas derivadas [1], cursores explícitos, valores default para parâmetros, as funções IIF, CHAR_LENGTH, TRIM, RDB$GET_CONTEXT e RDB$SET_CONTEXT, o operador IS [NOT] DISTINCT, os comandos EXECUTE BLOCK e COMMENT ON, a cláusula RETURNING, índices definidos por expressões, collates (PT_BR e WIN_PTBR) para o Brasil, suporte a Unicode, melhorias de performance relacionadas à nova implementação de índices e diversas mudanças no otimizador, backups físicos e incrementais com o NBackup e suporte a plataformas 64-bit.<br />
<br />
A versão 2.1 introduziu dezenas de novas funções internas, triggers de eventos de conexão e transação, tabelas temporárias, collates customizáveis com CREATE COLLATION, queries recursivas com Common Table Expression (CTE) [2], os comandos UPDATE OR INSERT e MERGE, a função agregada LIST, a possibilidade de uso de domains em PSQL, a interoperabilidade entre BLOBs e strings, tabelas de monitoração, o utilitário fbsvcmgr e diversas melhorias implementadas no protocolo de comunicação, melhorando a performance de comunicação cliente/servidor via internet.<br />
<br />
Diante de toda essa evolução, é importante ressaltar que toda alteração e nova funcionalidade do Firebird é pensada levando em consideração dois princípios estabelecidos pelo projeto: compatibilidade e padronização SQL. A compatibilidade é sempre levada extremamente a sério, e dificilmente algo que funciona em uma versão deixa de funcionar em outra, respeitando o investimento feito pelos desenvolvedores. Em relação ao padrão SQL, ele é sempre consultado e analisado em detalhes, e quando possível, as implementações são realizadas com base neste padrão.<br />
<br />
A versão 2.5, assim como as anteriores, possui diversas novas funcionalidades. Primeiramente, veremos sobre possíveis problemas durante o processo de migração. Em seguida, veremos sobre a nova arquitetura SuperClassic, que permite melhor aproveitamento de recursos e melhor desempenho em máquinas multiprocessadas, e as alterações diretamente relacionadas ao desenvolvimento. Os exemplos presentes nas listagem foram feitos para o ISQL, mas devem funcionar sem problemas em qualquer ferramenta.<br />
<br />
<div>
<b>Notas</b><br />
<br />
[1] - Tabela derivada (derived table) é o nome dado pelo padrão SQL a uma query usada na claúsula FROM de outra query. Por exemplo: SELECT X.* FROM (SELECT * FROM PESSOA) X. Neste caso, X é uma tabela derivada. Veja mais exemplos no <a href="http://www.firebirdsql.org/file/documentation/release_notes/html/rlsnotes207.html" target="_blank">release notes da versão 2.0</a>.<br />
<br />
[2] - Common Table Expression (CTE) é similar as tabelas derivadas, mas o nome da tabela é definido no começo da instrução com a cláusula WITH. Exemplo: WITH X AS (SELECT * FROM PESSOA) SELECT * FROM X. Com as CTEs é possível fazer queries hierárquicas (recursivas) usando-se WITH RECURSIVE e UNION ALL. Veja mais exemplos no <a href="http://www.firebirdsql.org/file/documentation/release_notes/html/rlsnotes210.html" target="_blank">release notes da versão 2.1</a>.</div>
Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-17852494685978866682013-12-18T11:34:00.000-02:002013-12-18T11:40:48.672-02:00Artigo "Novidades do Firebird 2.5"A partir de sexta-feira, dia 20/12/2013, começarei a postar o artigo <a href="http://asfernandes.blogspot.com.br/2011/01/novidades-do-firebird-25-revista.html" target="_blank">que escrevi</a> para a revista ClubeDelphi. Esse artigo saiu na edição #125 da revista, em dezembro de 2010.<br />
<br />
O artigo será postado em partes, conforme abaixo:<br />
<br />
- Introdução<br />
- Migrando de versões anteriores<br />
- A arquitetura SuperClassic<br />
- Character Sets e Collates<br />
- Comandos DDL (Data Definition Language)<br />
- Expressões, literais e funções<br />
- Linguagem PSQL<br />
- ConclusãoAdrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-5765516764758249962012-04-26T23:12:00.002-03:002012-04-27T00:01:15.484-03:00DSQL/BLR compilers internalsThis post is some raw notes and is not very understandable by people who never worked with this code. In fact, the old implementation was so ugly that it was not simple even for me (who is constantly working in this area) to achieve this result. It needed many tries and reverts, but IMNSHO ended very well. Also, this was a large work that took many time, and I'm just writing some records here.<br />
<br />
Back in 2006, just after being invited to take DSQL work, I started to think what would we need to do to improve the compilers (DSQL and BLR) internals. My look started at src/dsql/pass1.cpp and src/jrd/cmp.cpp. Till then, even the addition of a simple function was a nightmare. This dialog happened by Nickolay Samofatov and myself in September-2004:<br />
<br />
Adriano: I added the "Lower" function. I don't knew that it is so difficult. "Length" will be added using blr too?<br />
<br />
Nickolay: why difficult?
<br />
<br />
Nickolay: just fix 15 files or so :-)
<br />
<br />
So I spent some years fixing "15 files or so" to add each feature and became very bored. In v2.5, to implement ALTER CHARACTER SET and AUTONOMOUS TRANSACTIONS statements, I added a "compatibility layer" to implement statements in an more OO-way. I described the DDL work in <a href="http://asfernandes.blogspot.com.br/2009/08/ddl-execution-architecture-in-firebird_4841.html">this post</a>.
<br />
<br />
As I had promised in that post, it allowed to implement subroutines, as well packages.
<br />
<br />
Within the v3.0 development cycle started, it was clear that not only statements was needing this layer, but expressions too. Expressions are much more "interesting" than statements. There are many types of expressions, all of them were mangled in the (now removed!) ubiquitous dsql_nod/jrd_nod structures and algorithms. These types are record sources, values, booleans, aggregate values, windowed values and lists.
<br />
<br />
The compatibility expression layer allowed to implement window functions (more <a href="http://asfernandes.blogspot.com.br/2010/01/window-functions_19.html">here</a>, <a href="http://asfernandes.blogspot.com.br/2010/01/window-functions-part2-cumulative_24.html">here</a> and <a href="http://asfernandes.blogspot.com.br/2010/02/window-functions-part3-new-functions.html">here</a>), but at the same time it create more ugly code in the (internal) interfaces.
<br />
<br />
The complete removal of jrd_nod was easy and done a lot of time ago. But dsql_nod remained. It was a lot of code needing a complete refactor (rewrite), which now is finally done.
<br />
<br />
This is the Node classes hierarchy. Except lists, each of them has its inherited classes (omitted here).
<br />
<br />
Node<br />
--- DdlNode<br />
--- DmlNode<br />
------ StmtNode<br />
------ ExprNode<br />
--------- BoolExprNode<br />
--------- ValueExprNode<br />
------------ AggNode<br />
--------------- WinFuncNode<br />
--------- RecordSourceNode<br />
--------- ListExprNode<br />
------------ ValueListExprNode<br />
------------ RecSourceListExprNode<br />
<br />
As I said, much time was spent on this, but without it many other features were not possible (or viable).<br />
<br />
It's easy to say now that the old code was a crap (and that is what it was, really!), but many things are involved here (like C vs C++, bison vs btyacc). The main thing is that this rework was now possible, so it was done.Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com1tag:blogger.com,1999:blog-3443854162607009076.post-4587967420825815292011-10-22T01:15:00.001-02:002011-10-22T01:15:44.700-02:00Como se tornar (ou não) um "Firebird Developer"Recentemente eu divulguei em meu twitter que estava fazendo sete anos do meu primeiro commit no projeto Firebird. Daí citaram isso no FirebirdNews e em newsletter da Firebase.<br />
<br />
Estou dizendo isso porque apareceram algumas pessoas com aquele tipo comum de questionamento "Como entrar para o time Firebird?". O problema é que, como citado na newsletter da Firebase, desses sete anos pra cá nenhum desenvolvedor se juntou ao Firebird (core). Isso mesmo, com exceção de um ou outro patch específico (geralmente dos mantenedores das distros Linux), o Firebird é desenvolvido pelas mesmas poucas pessoas há mais de sete anos.<br />
<br />
Sempre respondi esses e-mails, mas geralmente a "vontade" da pessoa já termina aí. E olha que sempre respondi com mais educação do que estou usando pra escrever esse post.<br />
<br />
Então vou colocar o que realmente penso sobre isso. Em primeiro lugar, você não deve fazer essa pergunta "Como entrar para o time Firebird?". A primeira coisa é aprender a usar o Google e se surgir alguma dúvida que não tenha uma resposta, aí sim pergunte sobre ela.<br />
<br />
É normal que você tenha dificuldade pra "se inserir" no projeto. Eu comecei a acompanhar o desenvolvimento do Firebird em dezembro de 2003 e meu primeiro commit foi em setembro de 2004, apesar de estar trabalhando ativamente desde junho ou julho. O Claudio Valderrama costumava dizer que eu era o único que tinha aprendido o código em algumas semanas, mas como podem ver foi alguns meses :), sem falar que até hoje eu não gosto nem de ver certos subsistemas (hello PAG, CCH, SDW...).<br />
<br />
Outra coisa são suas habilidades. Não é normal que você não tenha no mínimo bons conhecimentos sobre C++, que é a linguagem usada no desenvolvimento do Firebird. Eu posso te afirmar com 98% de certeza que você não vai encontrar em um projeto open-source pessoas com vontade de te ajudar com coisas básicas.<br />
<br />
Digamos que você já esteja pensando que não quer isso (como todos os anteriores), mas tenha alguma dúvida ainda, então continuo minhas sugestões para que você não consiga :). Não leia todos os posts das listas de discussões. Também não leia e tente entender todas as alterações feitas no código, que são enviadas pra lista firebird-checkins. Acho que foi aqui que falhei, pois desde aquele dezembro de 2003 não deixei de ler nenhuma das milhares de mensagens. E tenho certeza que todos os outros desenvolvedores ativos fizeram e fazem o mesmo.<br />
<br />
Se você também se ofendeu com esse post (caso tenha sido um dos que fez aquela pergunta), é melhor não perder seu tempo e desistir logo. Quem acompanha as listas firebird-devel e firebird-architect (e a firebird-admins, mas essa é fechada), sabe do que estou falando. As vezes (pra não dizer, muitas vezes) as discussões partem pro lado pessoal, e isso é a pior parte de fazer parte do projeto. Isso não é uma exclusividade do Firebird. Comparando com o Linux, por exemplo, é só procurar alguma mensagem do Linus Torvals na lkml e ver como a coisa geralmente funciona.Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-9635163671134531422011-08-20T12:58:00.004-03:002011-09-01T00:08:07.225-03:00Beautiful fonts in UbuntuIn the old days, fonts in Linux were really ugly by default. There are patents involved, so it was possible to make them beautiful recompiling freetype with some options.<br />
<br />
Since some time, this is not necessary.<br />
<br />
But if you're like me, you may note that some fonts are very blurry in some applications, and you can't change that in the appearance config.<br />
<br />
To fix this, I put this <a href="http://pastebin.com/U0humUR9">.fonts.conf</a> in my home directory.
Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com1tag:blogger.com,1999:blog-3443854162607009076.post-29897191283890938942011-05-01T14:05:00.005-03:002011-05-01T14:19:25.455-03:00Ubuntu Natty Narwhal in VMware<div>Here are some tips to use Ubuntu 11.04 Natty Narwhal on VMware.<br /></div><div>First upgrade the host vmware (player) to the latest (3.1.4) version. Although the release notes mention nothing on Natty, the vmware-tools from this version compiles ok on the Natty kernel.<br /></div><div>You may have some luck with the open-vm-tools. I didn't had much. It didn't recognized the machine as a VM, but still worked. I was having problems with the video looking very ugly and was thinking it was a vmware-tools problem, but looks like not. Below is a workaround to run on the terminal which makes things beautiful again:<br /></div><div>killall gnome-settings-daemon</div><div>gnome-settings-daemon &</div>Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-56229038147569287882011-04-20T14:54:00.006-03:002011-04-20T15:01:07.742-03:00Alguns links de artigos e vídeos que acho interessantes<div style="background-color: transparent; "><span class="Apple-style-span" ><span class="Apple-style-span" style="font-size: 15px; white-space: pre-wrap;"><div style="background-color: transparent; font-family: 'Times New Roman'; white-space: normal; font-size: medium; "><span id="internal-source-marker_0.7166498028673232" style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 0); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; ">Segue alguns links de artigos e vídeos que acho interessantes:</span><br /><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 0); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span><br /><a href="http://www.ted.com/talks/lang/por_br/jason_fried_why_work_doesn_t_happen_at_work.html"><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 153); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">Porque não se trabalha no trabalho</span></a><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 0); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> - Jason Fried tem uma teoria radical sobre o trabalho, que diz que o escritório não é um bom lugar para fazê-lo.</span><br /><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 0); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span><br /><a href="http://www.superempreendedores.com/empreendedorismo/guy-kawasaki-a-arte-do-comeco"><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 153); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">A Arte do Começo</span></a><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 0); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> - Vídeo com Guy Kawasaki dando uma palestra sobre como se começar um negócio.</span><br /><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 0); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span><br /><a href="http://aurelianomartins.wordpress.com/2011/04/04/verdades-nao-tao-conhecidas-sobre-programacao/"><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 153); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">Verdades não tão conhecidas sobre programação</span></a><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 0); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> - Tradução de um artigo que fala sobre a diferença entre programadores bons e ruins.</span><br /><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 0); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span><br /><a href="http://akitaonrails.com/2009/03/30/off-topic-net-negative-producing-programmer"><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 153); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">Net Negative Producing Programmer</span></a><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 0); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> - Fábio Akita fala sobre as diferenças entre os Codificadores (cowboys) e os Desenvolvedores.</span><br /><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 0); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span><br /><a href="http://www.youtube.com/watch?v=XvU12J0aYo4&feature=player_embedded"><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 153); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">Ócio Criativo x Cowboy Coders</span></a><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 0); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> - Vídeo onde Daniel Cukier coloca a sua visão sobre a diferença entre Codificadores e Programadores, em alusão ao post (acima) do Fábio Akita.</span><br /><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 0); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "></span><br /><a href="http://java.mn/2011/03/02/the-future-java-developer/"><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 153); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; ">The Future Java Developer</span></a><span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 0, 0); background-color: transparent; font-weight: normal; font-style: normal; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; "> - O JavaMan Bruno Souza fala sobre o que desenvolvedores podem fazer para serem melhores profissionais no futuro (presente). Não é específico de Java.</span></div></span></span></div>Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-66672912630970135902011-01-01T20:05:00.006-02:002011-01-01T20:31:52.271-02:00Novidades do Firebird 2.5 - Revista ClubeDelphiSaiu na <a href="http://www.devmedia.com.br/post-18855-Revista-Clube-Delphi-Edicao-125.html">edição 125</a> da revista ClubeDelphi <a href="http://www.devmedia.com.br/post-18849-Firebird-2-5.html">o artigo</a> que escrevi sobre as novidades do Firebird 2.5. Esta edição também tem outra matéria sobre Firebird, entitulada "Aplicações com Firebird Embedded – Parte 1".<div>Já tinha recusado convites similares, mas desta vez resolvi topar o desafio. Não gosto muito de escrever, sou bastante perfeccionista e português não é uma das linguagens que eu domino (rs). Essa é uma das razões porque eu prefiro escrever em inglês no blog. Não que meu inglês seja bom, mas eu me sinto mais a vontade pra escrever mal. :)</div><div>Não vi a revista ainda. Espero que gostem, deu bastante trabalho.</div>Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com2tag:blogger.com,1999:blog-3443854162607009076.post-62673916644353604092010-12-18T10:36:00.002-02:002010-12-18T11:11:35.794-02:00Introducing the boolean datatypeThe support for a BOOLEAN datatype was the <a href="http://tracker.firebirdsql.org/browse/CORE-726">third most voted</a> feature in the Firebird tracker. The deal with it was about make it right and complete, having booleans expressions allowed where values are expected, and vice versa. Oracle did it wrong and they BOOLEAN is crap.<div>Yesterday I finished and committed this support for Firebird 3. You can use them like any other type. You can index it, aggregate by it and sort by it. If you have an index on a boolean field, you can also do indexed searches by its negated form (NOT field).</div><div>Three new literals are introduced: FALSE, TRUE and UNKNOWN (same as NULL).</div><div>Booleans are not implicitly convertible to any other datatype. But it's convertible to/from strings with CAST.</div><div>It's allowed to test booleans without compare with TRUE or FALSE. For example, "field1 OR field2" and "NOT field1" are valid expressions. It's also allowed to compare with others operators, including the new IS operator: "field1 IS FALSE".</div><div>Currently it has a terrible and bad hack. The new syntax would introduce a lot of parser conflicts related with trigger's INSERTING, UPDATING and DELETING expressions. These boolean expressions was non-reserved words and allowed to be used as column and variable names. The correct solution shall be to reserve these words and do not allow them to be used as names without double quotes.</div><div>As usual, this causes conflict opinions. I don't want to fight forever on this, so I make them work as triggers keywords in boolean expressions and as values in non-booleans expressions. This is much very compatible with previous versions, but is very confusing. For example, in "SELECT inserting, NOT inserting FROM test WHERE INSERTING and INSERTING IS TRUE" the INSERTING's are recognized as value, keyword, keyword and value.</div><div>I hope this clears people's minds and we have a better solution in the final version.</div>Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com3tag:blogger.com,1999:blog-3443854162607009076.post-54702210918733433132010-12-14T19:18:00.006-02:002010-12-14T21:00:41.264-02:00Problema com Java 1.6.0_22 e NF-e de SPTivemos um problema, em ambiente interno de testes, com os webservices da Nota Fiscal Eletrônica do estado de São Paulo. O sistema estava sendo migrado de sistema operacional HP-UX (com Java distribuído pela HP) para um novo servidor com Red Hat Enterprise Linux (com Java da <s>Sun</s> Oracle).<div>Ao acessar os webservices a aplicação congelava ou dava erros de "read timed out". O primeiro passo foi verificar se o servidor estava acessando a internet normalmente. Através do elinks era possível acessar sites via http e https normalmente. O webservice retornava corretamente o erro de falta de certificado cliente.</div><div>Depois tentei fazer conexões pela aplicação adicionando "?WSDL" às URLs. Nem o ambiente de homologação nem o de produção da NF-e funcionavam. Outros endereços http funcionavam normalmente pela aplicação. Pra debugar o problema, adicionamos a opção -Djavax.net.debug=all. A requisição era enviada mas não vinha a resposta.</div><div>Resolvi fazer o teste com os webservices de contingência do SCAN e funcionou. Analisando os logs da conexão, resolvi procurar sobre o termo no_renegotiation que estava aparecendo quando acontecia o erro.</div><div><a href="http://www.oracle.com/technetwork/java/javase/documentation/tlsreadme2-176330.html">Esta página</a> esclareceu o problema, que foi causado devido a uma alteração no Java para prevenir uma vulnerabilidade do protocolo TLS. Adicionamos as opções -Dsun.security.ssl.allowUnsafeRenegotiation=true e sun.security.ssl.allowLegacyHelloMessages=true até que o ambiente de SP seja atualizado.</div>Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-86660451151535000562010-10-04T21:16:00.009-03:002010-10-04T21:36:38.904-03:00Firebird 2.5 Introduces New Audit Features and Improved ScalabilityOctober 4, 2010<br /><br />The Firebird Project today announces Firebird 2.5, the fifth and newest major release of its open source relational database management system. Enhancements in this new release are pitched at better serving the needs of businesses of any scale, from embedded device to enterprise resource planning solutions.<br /><br />Philippe Makowski, President of the non-profit <a href="http://www.firebirdsql.org/pop/index.php?op=ffoundation">Firebird Foundation</a> observes that the Firebird 2.5 release is a very important step in Firebird's 10th anniversary year, not just for the Firebird Project but for the whole open-source world, too.<br /><br />"Today businesses all around the world are looking for mature, cost-effective solutions and Firebird 2.5 offers them a solution that is truly powerful and truly free", he noted.<br /><br />The mix of high performance, small footprint, supreme scalability, silent and simple installation and royalty-free deployment make Firebird a highly attractive choice for all types of software developers and vendors. Firebird deployments are well established around the globe, serving data to hundreds of thousands of business systems with hundreds of users and databases exceeding 300GB.<br /><br />Known Firebird installations number more than 2,000 each day, according to download statistics.<br /><br />"Many of our customers have Firebird databases with sizes from 200GB to 400GB and they keep growing", said Stewart Spink, CTO of <a href="http://www.watermarktech.co.uk/">Watermark Software</a>. "The performance improvements in Firebird 2.5 will ensure that their future demands will be satisfied completely."<br /><br />Alexander Shaposhnikov, CIO of medical distributor <a href="http://www.profitmed.net/">Profitmed</a> predicts that Firebird 2.5 will support the growth of Profitmed's business. "Currently we have a 65Gb database and 250 active users working 24x7. We intend to double both the size of the database and the number of users in two years and we have chosen Firebird 2.5 for this business-critical task."<br /><br />Firebird binaries are distributed for a variety of system and hardware platforms: Windows, Linux, MacOS, Solaris, HP-UX and more. Firebird runs on on x86, x64, PowerPC, Sparc and other hardware platforms, providing an easy migration mechanism between these diverse platforms.<br /><br />The V.2.5 release binaries ship for 32-bit and 64-bit Windows and Linux, with MacOSX x86 to follow. Other POSIX platform builds are likely to appear before the year is out, in response to demand.<br /><br />New features of Firebird 2.5<br /><ul><li>New SuperClassic Architecture Firebird 2.5 introduces a new architecture, tagged "SuperClassic", to gain better leverage from multi-core and multi-CPU hardware environments and improve resource usage for systems with large numbers of users and huge databases.</li></ul><ul><li>Audit System audit tracing and user trace sessions via the Services API enable nearly real-time monitoring and analysis of everything going on in a database</li></ul><ul><li>Cross-database queries Firebird 2.5 opens the way for Firebird database instances to query one another and to exchange information</li></ul><ul><li>Enhanced user management User management becomes accessible and flexible through SQL requests submitted from user databases</li></ul><ul><li>Other features include autonomous transactions within PSQL modules (stored procedures, triggers, SQL blocks), support for regular expressions as arguments in SQL using the SIMILAR TO predicate, asynchronous cancellation of connections, enhancements of monitoring capabilities and much more.</li></ul>Paul Beach, President and CEO of <a href="http://www.ibphoenix.com/">IBPhoenix</a>, an organisation that offers professional services and contributes to Firebird development, considers the new security features and the impressive scaling capability of Firebird 2.5 will be welcomed by many existing Firebird users.<br /><br />"In particular, it will help those in the finance and health industries to meet the growing requirements of their businesses", he notes, "especially in pushing the limits of performance."<br /><br />David Wilder, CTO of <a href="http://www.basx.com.au/">Bas-X</a>, welcomed the Firebird 2.5 release for its improved useability and flexibility. "It will enable our customers to turn over more transactions and run more concurrent users on the same hardware," he said.<br /><br /><b>Pricing and Availability</b><br /><br />Firebird 2.5 is an open source database system that is available free of charge for any kind of usage, be it commercial, educational, non-profit or simply for private use. Both binary packages and the complete source code can be <a href="http://www.firebirdsql.org/index.php?op=files&id=engine_250">downloaded</a> at no cost through the Firebird Project website for immediate installation. No registration or activation is required.<br /><br /><b>About the Firebird Foundation</b><br /><br />The <a href="http://www.firebirdsql.org/index.php?op=ffoundation">Firebird Foundation</a> is a non-profit organization with the goal to support the development and growth of the Firebird relational database system. The Foundation was incorporated in 2002 and is currently supported by more than <a href="http://www.firebirdsql.org/index.php?op=ffoundation&id=members_alpha">300 active members</a>, several of whom are also <a href="http://www.firebirdsql.org/index.php?op=ffoundation&id=sponsorship">cash sponsors</a>. It also accepts and manages donations of cash and resources from persons and organisations that are not regular members. The Foundation redistributes these funds as grants to some of the key workers in the Firebird Project. The Firebird Project has no other source of income.<br /><br />Media Contact: Alexey Kovyazin * +7 910 402 94 34 * admin AT mindthebird DOT comAdrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com0tag:blogger.com,1999:blog-3443854162607009076.post-54670093880142742952010-09-30T20:53:00.003-03:002010-10-01T00:44:07.918-03:00Firebird 2.5 launch<a href="http://www.firebirdsql.org">Firebird</a> 2.5 release date is set - it will be October 4th, 2010.<br /><br />Please join Philippe Makowski, President of Firebird Foundation, and Dmitry Yemanov, lead Firebird developer, at the <a href="https://www.livemeeting.com/cc/fbcon2010/join?id=46D79S&role=attend">Launch Webinar</a> devoted to the 5th major release of Firebird.<br /><br />It will take place at October 4th, 2010, at 13:00 GMT (10:00 pelo horário de Brasília).<br /><br />If you have any questions regarding Firebird 2.5, please feel free to contact <a href="http://www.mindthebird.com">Mind the Bird</a> campaign at <a href="mailto:launch@mindthebird.com">launch@mindthebird.com</a>.Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com2tag:blogger.com,1999:blog-3443854162607009076.post-75479371720846287872010-07-31T14:31:00.002-03:002010-07-31T14:39:35.548-03:00Firebird 10th anniversary. How I came to it.July 31th, 2010. Today <a href="http://www.firebirdsql.org/">Firebird</a> completes its 10th anniversary. The Firebird website has a set of <a href="http://firebirdsql.org/index.php?op=history">history documents</a> about how that started. It’s something you must read if you’re interested in Firebird.<br /><br />I’m sometimes asked about how I became one of its team members. So I’m going to tell something about this.<br /><br />First things first. My first contact with InterBase was with the one present in the Delphi 3 CD. Searches says it was InterBase 4.2. I must say I didn’t like it too much. But my main problem at the time was with SQL. Not with its syntax, but with the idea of manipulating a database with text commands, and not via an API in a programming language. Fortunately, I was a child and grew up since then. :-)<br /><br />The second important thing I remember about InterBase was about it becoming open source. This was something I liked, but just forgot soon later.<br /><br />Then sometime later I came to the <a href="http://info.abril.com.br/downloads">Info</a> download site and it had Firebird with a text saying something like “Download it, while it’s free”. I downloaded it (the 1.0 version) and saw on its website that there was no plan to make it non-free. I started using and liked it. What most attracted me was it excellent transaction control mechanism.<br /><br />I then started using the 1.5 RC versions and found a security bug on it. I tried to report on the SourceForge bug tracker without success. So I subscribed myself to firebird-devels mailing list and reported it there. That happened around in December 2003, and I never leaved the list since then. :-)<br /><br />Lurking at firebird-devel was a challenge. I didn’t understand much English nor the technical talks, but I stayed there reading every message. I started to read the source code and understand the subsystems. I then started following firebird-checkins mailing list, where I could better understand how each feature/fix got implemented.<br /><br />Around July 2004, I joined the Firebird PT_BR project to adapt for Firebird 1.5 the Brazilian collation done by Paulo Henrique Albanez for Firebird 1.0. I proposed different approach to definitively integrate it in Firebird and it was also rejected. So I got the work to do the “right” changes to the Firebird International Language (INTL) subsystem. In September 2004 I officially joined the project.<br /><br />What’s more nice about being there is that I can work with very competent team, delivering a good software to millions of people. And just doing something I really like, designing features, programming in C++ and working with compiler (SQL / PSQL) implementation...<br /><br />Long live Firebird!Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com2tag:blogger.com,1999:blog-3443854162607009076.post-30478283756552710722010-02-19T23:46:00.001-02:002010-02-19T23:47:10.871-02:00Window functions (part3) - new functionsIn the <a href="http://asfernandes.blogspot.com/2010/01/window-functions_19.html" id="odpv" title="first">first</a> and the <a href="http://asfernandes.blogspot.com/2010/01/window-functions-part2-cumulative_24.html" id="wif4" style="color:#551a8b" title="second">second</a> part of window function series, I talked about the <font face="'Courier New'">OVER</font> clause, with/without partitions and with/without ordering. Till then, no new function had been introduced, so it has about the already existing aggregate functions.<br><br><div>Now, new window-only functions has been introduced. I'll separate them in two groups: ranking and navigational. Both set of functions can be used with/without partition/ordering, but them does not make much sense without ordering.</div><br><div><b>Ranking functions (DENSE_RANK, RANK and ROW_NUMBER):</b> with these functions, one can create different type of incremental counters. Think about <font face="'Courier New'">SUM(1) OVER (ORDER BY SALARY)</font>, these functions does this type of thing, but all of them in different ways. Lets see an example query, also comparing with the SUM behavior.</div><br><div><font face="'courier new'">select<br></font><font face="'courier new'"> id,</font></div><div><font face="'courier new'"> salary,</font></div><div><font face="'courier new'"><font face="'courier new'"><font face="'courier new'"> dense_rank() over (order by salary),<br></font><font face="'courier new'"> rank() over (order by salary),<br></font> row_number() over (order by salary),<br></font> sum(1) over (order by salary)<br></font><font face="'courier new'"> from employee</font><br><div><font face="'Courier New'"> order by salary;</font></div><br></div>And the result set:<br><br><table border="1" bordercolor="#000000" cellpadding="3" cellspacing="0" id="ae:0"><tbody><tr style="text-align:left"><td style="text-align:right" width="16.666666666666668%"><font size="2">id</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">salary</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">dense_rank</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">rank</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">row_number</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">sum</font></td></tr><tr style="text-align:left"><td style="text-align:right" width="16.666666666666668%"><font size="2">3</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">8.00</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">1</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">1</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">1</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">1</font></td></tr><tr style="text-align:left"><td style="text-align:right" width="16.666666666666668%"><font size="2">4</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">9.00</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">2</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">2</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">2</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">2</font></td></tr><tr style="text-align:left"><td style="text-align:right" width="16.666666666666668%"><font size="2">1</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">10.00</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">3</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">3</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">3</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">4</font></td></tr><tr style="text-align:left"><td style="text-align:right" width="16.666666666666668%"><font size="2">5</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">10.00</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">3</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">3</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">4</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">4</font></td></tr><tr style="text-align:left"><td style="text-align:right" width="16.666666666666668%"><font size="2">2</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">12.00</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">4</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">5</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">5</font></td><td style="text-align:right" width="16.666666666666668%"><font size="2">5</font></td></tr></tbody></table><br>As you see, the functions differs when repeated values are found in the order key (the salary of 10.00). With DENSE_RANK, no gaps are created and all repeated values receive the same counter. With RANK, the initial counter is used for all repeated values, but it make gaps so the next non-repeating value (the salary of 12.00) does not consider the previously repeated values as in different positions. With ROW_NUMBER, each line receives an incremental value. And SUM(1) is very like RANK, but the value is computed after all repeated values are summed, so the gap is before the repeated values.<br><br><div><b>Navigational functions (LAG and LEAD):</b> with these functions, an expression could get the value of a previously (LAG) or a posterior (LEAD) row of the query. Follow the demonstrating query.</div><br><div><div>select</div><div> id,</div><div> salary,</div><div> lag(salary) over (order by salary),</div><div> lead(salary) over (order by salary)</div><div> from employee</div><div> order by salary;</div><br>And the result set:</div><br><table border="1" bordercolor="#000000" cellpadding="3" cellspacing="0" id="l7bi"><tbody><tr style="text-align:left"><td style="text-align:right" width="25%"><font size="2">id</font></td><td style="text-align:right" width="25%"><font size="2">salary</font></td><td style="text-align:right" width="25%"><font size="2">lag</font></td><td style="text-align:right" width="25%"><font size="2">lead</font></td></tr><tr style="text-align:left"><td style="text-align:right" width="25%"><font size="2">3</font></td><td style="text-align:right" width="25%"><font size="2">8.00</font></td><td style="text-align:right" width="25%"><font size="2"><null></font></td><td style="text-align:right" width="25%"><font size="2">9.00</font></td></tr><tr style="text-align:left"><td style="text-align:right" width="25%"><font size="2">4</font></td><td style="text-align:right" width="25%"><font size="2">9.00</font></td><td style="text-align:right" width="25%"><font size="2">8.00</font></td><td style="text-align:right" width="25%"><font size="2">10.00</font></td></tr><tr style="text-align:left"><td style="text-align:right" width="25%"><font size="2">1</font></td><td style="text-align:right" width="25%"><font size="2">10.00</font></td><td style="text-align:right" width="25%"><font size="2">9.00</font></td><td style="text-align:right" width="25%"><font size="2">10.00</font></td></tr><tr style="text-align:left"><td style="text-align:right" width="25%"><font size="2">5</font></td><td style="text-align:right" width="25%"><font size="2">10.00</font></td><td style="text-align:right" width="25%"><font size="2">10.00</font></td><td style="text-align:right" width="25%"><font size="2">12.00</font></td></tr><tr style="text-align:left"><td style="text-align:right" width="25%"><font size="2">2</font></td><td style="text-align:right" width="25%"><font size="2">12.00</font></td><td style="text-align:right" width="25%"><font size="2">10.00</font></td><td style="text-align:right" width="25%"><font size="2"><null></font></td></tr></tbody></table><br>The functions have a second argument, that is implicitly 1, which means the number of previously/posterior rows will be queried. If this row does not exist, <null> is returned.<br><br><div>And of course, you can use these functions as expressions and compute, for example, the difference of an employee salary from the one greater and/or lesser.<br></div><br>Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com2tag:blogger.com,1999:blog-3443854162607009076.post-10423763081719305772010-02-13T23:28:00.004-02:002010-02-14T01:16:05.434-02:00Firebird History in 9 minutes video<div><span class="Apple-style-span" style="font-family:verdana;">This is a <a href="http://vis.cs.ucdavis.edu/~ogawa/codeswarm/" target="_blank">code_swarm</a> of the <a href="http://firebird.cvs.sourceforge.net/firebird/firebird2/" target="_blank">firebird2</a> tree.</span></div><br /><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/c97fRd3cBn0&hl=pt_BR&fs=1&"><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="http://www.youtube.com/v/c97fRd3cBn0&hl=pt_BR&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>Adrianohttp://www.blogger.com/profile/07470899351244413501noreply@blogger.com2