Squirrel Erro: Create/Alter Procedure
Ao tentar executar algum comando de criação de procedures, views, triggers, etc, usando o Squirrel temos o seguinte erro:
Error: ‘CREATE/ALTER PROCEDURE’ must be the first statement in a query batch.
SQLState: S0001
ErrorCode: 111
Para isso não ocorrer, basta desmarcar a opção “limit rows”, que vem marcada por default.
Detalhes… o erro poderia ser mais amigável…
Salvando resultado de consultas em arquivo no SQL Server
Um breve exemplo de como salvar consultas ou resultado de uma Stored Procedure em um arquivo texto, utilizando MS SQL Server 2005.
Para fazer esta tarefa vamos utilizar a procedure xp_cmdshell disponível no banco master, juntamente com o comando do windows sqlcmd a rotina ficaria assim:
declare @servidor varchar(30), @usuario varchar(20), @senha varchar(20), @banco varchar(30), @procedure varchar(80), @arquivoFisico varchar(30), @comando varchar(250)set @servidor = 'localhost'
set @usuario = 'sa'
set @senha = 'sa'
set @banco = 'NomeDoSeuBanco'
set @procedure = 'select * from tabela ' --poderia ser uma stored Procedure também
set @arquivoFisico = 'c:\saida.csv'
set @comando = 'sqlcmd -S '+@servidor+' -U '+@usuario+' -P '+@senha+' -d '+@banco+' -q "'+@Procedure+'" -s ";" -f 65001 -o '+@arquivoFisicoexec master.dbo.xp_cmdshell @comando
No nosso caso o comando sqlcmd está recebendo como parâmetros:
-S Servidor
-U Usuario
-P Senha
-d Banco de dados
-q Instrucao SQL
-s Separador de campos dentro do arquivo texto, no nosso caso, ponto e virgula (poderia ser virgula)
-f 65001 determinando que o arquivo seja gerado com encode UTF-8
-o Saida Caminho fisico
Caso o SQL Server bloqueie o acesso a procedure xp_cmdshell é só habilita-la.
SQL Server blocked access to procedure ‘sys.xp_cmdshell’
If you get this message:
SQL Server blocked access to procedure ‘sys.xp_cmdshell’ of component ‘xp_cmdshell’ because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of ‘xp_cmdshell’ by using sp_configure. For more information about enabling ‘xp_cmdshell’, see “Surface Area Configuration” in SQL Server Books Online.
That’s because, by default, xp_cmdshell is disabled in SQL Server 2005 for security reasons.
To turn it on, run this script:
EXECUTE SP_CONFIGURE 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
GOEXECUTE SP_CONFIGURE 'xp_cmdshell', '1'
RECONFIGURE WITH OVERRIDE
GOEXECUTE SP_CONFIGURE 'show advanced options', 0
RECONFIGURE WITH OVERRIDE
GO
Melhorando a produtividade com a configuração do Eclipse
Configurei o meu eclipse desta forma e na minha opinião melhorou a produtividade.
General > Appearance Marcar "show traditional style tabs" Desmarcar "enable animations"General > Editor > Text Editor Marcar "show line numbers"
General > Editor > Text Editor > Spelling Desmarcar "Enable spell check"
Java > Editor > Content Assist Marcar "completion overwrites" Marcar "insert common prefixes automatically" Marcar "guess filled method arguments"
Java > Editor > Typing Marcar "Semicolons" Marcar "Braces"
Java > Editor > Save Actions Marcar "Perform the selected actions on save" Marcar "Organize imports" Marcar "Additional actions" e clicar no botão "Configure...": Aba Code style: Marcar "Use blocks in if/while/for/do statements" e selecionar "always" Aba Unecessary Code: Marcar "Remove unused imports" Marcar "Remove unecessary casts" Aba Missing Code: Marcar "Add missing annotations", "@Override" e "@Deprecated" Aba Code Organizing: Marcar "Remove trailling whitespace" e selecionar "all lines"
Java > Compiler > Errors/Warnings: Mudar para "ignore" as opções da seção "Generic Types" - melhor do que ficar adicionando @SuppressWarnings
Java > Debug Desmarcar "Suspend execution on uncaught exceptions"
Error running JSF with Jboss
Error: The specified InjectionProvider implementation ‘org.jboss.web.jsf.integration.injection.JBossDelegatingInjectionProvider’ does not implement the InjectionProvider interface.
Solution:
You need to remove the bundled JSF implementation. To do so you need to comment/remove the following from the web.xml found under jboss-4.2.0.GA\server\\deploy\jboss-web.deployer\conf.
Under jboss 5.0.0GA jboss-5.0.0.GA\server\default\deployers\jbossweb.deployer\web.xml
< !-- Comment/Remove this -- >
< !-- Configures JSF for a web application if the javax.faces.webapp.FacesServlet is declared -- >
< !-- in web.xml. -- >
< !--
< listener>
< listener-class>org.jboss.web.jsf.integration.config.JBossJSFConfigureListener
< /listener>
-->
< !-- Comment/Remove this -- >
< !-- Listens to all web app lifecycle events so that @PreDestroy can be called on -- >
< !-- JSF managed beans that go out of scope. You can comment this out if you -- >
< !-- don't use JSF or you don't use annotations on your managed beans. -- >
< !--
< listener>
< listener-class>com.sun.faces.application.WebappLifecycleListener< /listener-class>
< /listener>
-- >
Sequência de Fibonacci em Ruby e Java
Escrevendo a sequência de Fibonacci em Ruby
x, y = 0, 1 10.times do puts y x, y = y, x + y end
e em java…
class Fib {
public static void main (String args[]) {
int x = 0;
int y = 1;
int total = 1;
for (int i=0; i<10; i++) {
System.out.println(total);
total = x+y;
x = y;
y = total;
}
}
}
Resultado em ambos os casos:
1
1
2
3
5
8
13
21
34
55
*Depois que se aprende o básico do Ruby, o básico do Java fica complexo demais…
Traduzindo labels no active_scaffold
Juntamente com minhas dúvidas, percebi que outras pessoas também questionaram como traduzir alguns labels no active_scaffold.
Pois bem, descobri duas maneiras para traduzir as expressões “Create”, “Edit”, “Delete”, “Show”, “Found”, etc, que aparecem nas views geradas automaticamente. A primeira seria através do application.rb adicionar o código:
ActiveScaffold.set_defaults do |config|
config.ignore_columns.add [:created_at, :updated_at, :lock_version]
config.create.link.label = “Novo”
config.update.link.label = “Alterar”
config.delete.link.label = “Excluir”
config.show.link.label = “Exibir”
end
E a outra forma, mais drástica, seria acessar os arquivos .rb que ficam na pasta vendor/plugins/active_scaffold/lib/config e alterar os labels da maneira que quisermos.
Problemas com active_scaffold
Procurando por plugins ajax para Rails no google, constatei que um dos mais populares atualmente é o active_scaffold. Acessei o tutorial deste plugin. Executei todas as instruções, passo a passo, mas para minha surpresa tive um pequeno problema de incompatibilidade de versões (rails 2.1.0) de forma que não conseguia nem startar a aplicação!
Como eu segui a risca todo passo a passo do tutorial, não entendi o que havia feito de errado, mas vamos as considerações:
No github, peguei a seguinte versão: git://github.com/neves/active_scaffold.git
Adicionai as linhas abaixo no layout
<%= javascript_include_tag :defaults %> <%= active_scaffold_includes %>
E finalmente, no controller:
class UserController < ApplicationController active_scaffold :user end
Só isso já é o suficiente para o active_scaffold rodar!
PORÉM, ao continuar lendo o tutorial, já no final temos as recomendações temos:
“Generating scaffold_resources”
If you are starting up a new application and want to use controller resources and RESTful routing,
then you should be aware that script/generate scaffold_resources requires some tweaking to operate with ActiveScaffold.
After running this generator, you’ll want to open up the generated controller, empty out all the built-in Rails scaffolding,
and replace it with the active_scaffold :my_model call.
Then, you’ll want to open up config/routes.rb and edit the new map.resources line and add an :active_scaffold => true argument.
É neste ponto que está o problema. Alterando o arquivo config/routes.rb e adicionando a linha :active_scaffold => true,
o servidor não inicializa e não é possível prosseguir. O erro que mostra é de incompatibilidade entre a versão do active_scaffold com a versão do rails.
Como estou iniciando em RoR, limitei-me a gerar o scaffold da forma convencional e alterar manualmente os controllers. Isto é o suficiente para fazê-lo funcionar. Caso alguém conheça mais profundamente sobre este assunto, fica aberto para comentários que venham a agregar valor!
Apresentação
Prezados,
Estou iniciando este blog para centralizar (e compartilhar) informações que me foram (e são) úteis na área de desenvolvimento de sistemas. Inicialmente escreverei sobre Rails, que é uma linguagem que estou aprendendo e com isso surgem muitas dúvidas.
