Tecnologia do Blogger.
RSS

RES: [androidbrasil-dev] Criar várias tabelas, melhor método

Assim:

 

private static final String[] SCRIPT_DATABASE_CREATE = new String[] { DATABASE_CREATE_CLIENTES, DATABASE_CREATE_CARROS… demais constantes}

 

Tenho essas constantes:

 

//  CRIA A TABELA CLIENTES

private static final String DATABASE_CREATE_CLIENTES = "create table clientes (id_Cliente integer primary key autoincrement, nome text, data text, telefone text, celular text, email text);";

 

//  CRIA A TABELA CARROS   

private static final String DATABASE_CREATE_CARROS = "create table veiculos (id_Veiculo integer primary key autoincrement,     

idCliente integer,  idTipoVeiculo integer, modelo text, placa text, FOREIGN KEY (idCliente) REFERENCES clientes(idCliente), FOREIGN KEY (id_TipoVeiculo) REFERENCES tipo_veiculo (id_TipoVeiculo));";

//  CRIA A TABELA TIPO_VEÍCULO

private static final String DATABASE_CREATE_TIPO_VEICULO = "create table tipo_veiculo (id_TipoVeiculo integer primary key autoincrement, descricao_tipo text));";

//  CRIA A TABELA SERVICOS

private static final String DATABASE_CREATE_SERVICOS = "create table servicos (id_Servico integer primary key autoincrement,  id_TipoVeiculo integer, descricao_ser text, valor text, FOREIGN KEY (id_TipoVeiculo) REFERENCES tipo_veiculo (id_TipoVeiculo));";

//  CRIA A TABELA HORARIOS

private static final String DATABASE_CREATE_HORARIOS = "create table horarios (id_Horario integer primary key autoincrement,  horario text);";

//  CRIA A TABELA OS

private static final String DATABASE_CREATE_OS = "create table os (id_Os integer primary key autoincrement, id_Cliente integer,     

id_Servico integer, id_Horario integer , modelo text, placa text, mecanico text, data text, FOREIGN KEY (id_Cliente) REFERENCES clientes (id_Cliente), FOREIGN KEY (id_Servico) REFERENCES servicos (id_Servico), FOREIGN KEY (id_Horario) REFERENCES horarios (id_Horario));";

Aí executaria assim:

db.execSQL(SCRIPT_DATABASE_CREATE);

 

Não entendi o lance do laço for também.

 

Att,

Frederico Brigatte

frederico.brigatte@gmail.com

 

De: androidbrasil-dev@googlegroups.com [mailto:androidbrasil-dev@googlegroups.com] Em nome de Rudson Lima
Enviada em: quinta-feira, 25 de julho de 2013 15:27
Para: androidbrasil-dev@googlegroups.com
Assunto: Re: [androidbrasil-dev] Criar várias tabelas, melhor método

 

Vc num já tem os sql nas constantes? Joga as constantes no String[]

 

Em 25 de julho de 2013 15:19, Frederico Brigatte <frederico.brigatte@gmail.com> escreveu:

1.  private static final String[] SCRIPT_DATABASE_CREATE = new String[] {    

2.      

3.      

4.  "CREATE TABLE IF NOT EXISTS CadUsuario(codigoUsuario INTEGER PRIMARY KEY autoincrement NOT NULL, codigo INTEGER NOT NULL,  login TEXT NOT NULL, senha TEXT NOT NULL);",       

5.            

6.            "CREATE TABLE IF NOT EXISTS CabecalhoPedido( idCabecalhoPedido INTEGER PRIMARY KEY  autoincrement NOT NULL, pedidoNumero INT NOT NULL,  codigoUsuario INTEGER NOT NULL, "+      

7.            " pedidoClienteDocumento TEXT, pedidoClienteInscricaoEstadual TEXT, pedidoClienteRazaoSocial TEXT, " +      

8.            " pedidoClienteEndereco TEXT, pedidoClienteCidade TEXT, pedidoClienteEstado TEXT, pedidoClienteCep TEXT, " +      

9.            " pedidoDataEmissao TEXT, pedidoValorTotal TEXT, pedidoCodCondicaoPag TEXT, pedidoCondicaoPag TEXT, pedidoLiberado TEXT, statusPedido TEXT, "+      

10.           " FOREIGN KEY(codigoUsuario) REFERENCES CadUsuario(codigoUsuario));",      

11.                 

12.           "CREATE TABLE IF NOT EXISTS AprovaPedido( pedidoNumero INT PRIMARY KEY NOT NULL, codigoUsuario INTEGER NOT NULL, aprovada TEXT NOT NULL, "+      

13.           " FOREIGN KEY(pedidoNumero) REFERENCES   CabecalhoPedido(pedidoNumero));"      

14.     

15.  }

Aí executaria assim:

 

db.execSQL(SCRIPT_DATABASE_CREATE);

 

 

Att,

Frederico Brigatte

frederico.brigatte@gmail.com

 

De: androidbrasil-dev@googlegroups.com [mailto:androidbrasil-dev@googlegroups.com] Em nome de Felipe Aron
Enviada em: quinta-feira, 25 de julho de 2013 14:51
Para: androidbrasil-dev@googlegroups.com
Assunto: Re: [androidbrasil-dev] Criar várias tabelas, melhor método

 

Depois das SQLs prontas (String) crie um array String[] e jogue as SQLs dentro.

 

Depois só fazer um for (String sql : seuArrayString) { db.execSQL(sql); }

 

2013/7/25 Frederico Brigatte <frederico.brigatte@gmail.com>

Meus amigos, tenho o seguinte script para montar as tabelas:

 

//  CRIA A TABELA CLIENTES

private static final String DATABASE_CREATE_CLIENTES = "create table clientes (id_Cliente integer primary key autoincrement, nome text, data text, telefone text, celular text, email text);";

   

 

//  CRIA A TABELA CARROS   

private static final String DATABASE_CREATE_CARROS = "create table veiculos (id_Veiculo integer primary key autoincrement,     

idCliente integer,  idTipoVeiculo integer, modelo text, placa text, FOREIGN KEY (idCliente) REFERENCES clientes(idCliente), FOREIGN KEY (id_TipoVeiculo) REFERENCES tipo_veiculo (id_TipoVeiculo));";

   

//  CRIA A TABELA TIPO_VEÍCULO

private static final String DATABASE_CREATE_TIPO_VEICULO = "create table tipo_veiculo (id_TipoVeiculo integer primary key autoincrement, descricao_tipo text));";

 

//  CRIA A TABELA SERVICOS

private static final String DATABASE_CREATE_SERVICOS = "create table servicos (id_Servico integer primary key autoincrement,  id_TipoVeiculo integer, descricao_ser text, valor text, FOREIGN KEY (id_TipoVeiculo) REFERENCES tipo_veiculo (id_TipoVeiculo));";

   

//  CRIA A TABELA HORARIOS

private static final String DATABASE_CREATE_HORARIOS = "create table horarios (id_Horario integer primary key autoincrement,  horario text);";

 

//  CRIA A TABELA OS

private static final String DATABASE_CREATE_OS = "create table os (id_Os integer primary key autoincrement, id_Cliente integer,     

id_Servico integer, id_Horario integer , modelo text, placa text, mecanico text, data text, FOREIGN KEY (id_Cliente) REFERENCES clientes (id_Cliente), FOREIGN KEY (id_Servico) REFERENCES servicos (id_Servico), FOREIGN KEY (id_Horario) REFERENCES horarios (id_Horario));";

 

 

db.execSQL(sqlClientes);

db.execSQL(sqlOutraTabela);

 

 

Qual o melhor método para criar as tabelas e o banco usando esse script ou StringBuilder?

 

 

 

Att,

Frederico Brigatte

frederico.brigatte@gmail.com

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



 

--

Analista-Programador

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 




--

Atenciosamente,

Rudson Lima

+ Desenvolvedor Delphi - NpInfo
+ Desenvolvedor Android - NpInfo

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário