Fórum Gravando dados em query #151487

02/04/2003

0

Olá pessoal,

Estou trabalhando com o SQL 7.0 e Delphi 5. Tenho umas tabelas que são muito grandes e estou pensando em deixar de utilizar o TTable e passar a usar TQuery. Como faço para salvar as alterações efetuadas na consulta direto no banco de dados ? Esta forma de trabalhar é segura ?

Grato,

José


Anonymous

Anonymous

Responder

Posts

02/04/2003

Wallace

José,

Vc poderia comecar passando a propriedade RequestLive para True. Mas existem algumas restricoes no SQL, como:

* nao pode existir GROUP BY, HAVING.
* ORDER BY com uma coluna que nao possui indice
* nao pode usar distinct
* nao pode usar Join
* nao pode usar subquery


Bom... se isto nao for problema, tudo bem. Dá para continuar. Bom... tem um probleminha com esta estratégica. Quando vc insere um registro, vc vai precisar fechar e abrir novamente a consulta. Infelizmente o conteudo do dataset é uma foto, e vc precisa atualiza-la. Na medida que vc for caminhando, vai descobrir que o recurso de CachedUpdates será muito interessante.

Bom... eu recomendo o seguinte: utilize o ClientDataSet. Lique ele num Provider e este último em uma Query. Utilize o providerflags dos fields da query e vc podera colocar join nesta última. Utilize o cache do clientdataset e implementar interfaces sofisticadas.

Nao tem jeito. Se um dia vc tiver ue mudar para DBExpress, vai ter de dominar o ClientDataSet.


Responder

Gostei + 0

03/04/2003

Anonymous

Olá pessoal, Estou trabalhando com o SQL 7.0 e Delphi 5. Tenho umas tabelas que são muito grandes e estou pensando em deixar de utilizar o TTable e passar a usar TQuery. Como faço para salvar as alterações efetuadas na consulta direto no banco de dados ? Esta forma de trabalhar é segura ? Grato, José


Siga o exemplo que dara certo

[color=blue:4200d4177f] SQL_Clientes.Close;
SQL_Clientes.Sql.Clear;
SQL_Clientes.SQL.ADD(´ INSERT INTO Clientes ´);
SQL_Clientes.SQL.ADD(´ (Cod_Cliente´);
SQL_Clientes.SQL.ADD(´ ,Cliente´);
SQL_Clientes.SQL.ADD(´ ,Endereco´);
SQL_Clientes.SQL.ADD(´ ,Municipio´);
SQL_Clientes.SQL.ADD(´ ,Bairro´);
If ME_DataCad.Text <> (´ / / ´) Then
SQL_Clientes.SQL.ADD(´ ,DataCad´);
SQL_Clientes.SQL.ADD(´ ,Cep´);
SQL_Clientes.SQL.ADD(´ ,UF´);
If ME_Fone.Text <> ´ ( XX ) - ´ Then
SQL_Clientes.SQL.ADD(´ ,Fone´);
If ME_Celular.Text <> ´( ) - ´ Then
SQL_Clientes.SQL.ADD(´ ,Celular´);
SQL_Clientes.SQL.ADD(´ ,InsEst´);
If ME_CNPJ.Text <> ´ . . / - ´ Then
SQL_Clientes.SQL.ADD(´ ,CNPJ´);
IF ME_CPF.Text <> ´ . . - ´ Then
SQL_Clientes.SQL.ADD(´ ,CPF´);
SQL_Clientes.SQL.ADD(´ ,Obs) ´);

SQL_Clientes.SQL.ADD(´ VALUES (´´+IntToStr(CodigoCliente)+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Edit_Cliente.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Edit_Endereco.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Edit_Municipio.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Edit_Bairro.Text+´´ ´);
If ME_DataCad.Text <> (´ / / ´) Then
SQL_Clientes.SQL.ADD(´ ,´´+FORMATDATETIME(´mm/dd/yyyy´, StrToDate(ME_DataCad.Text))+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Edit_Cep.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Edit_UF.Text+´´ ´);
If ME_Fone.Text <> ´ ( XX ) - ´ Then
SQL_Clientes.SQL.ADD(´ ,´´+ME_Fone.Text+´´ ´);
If ME_Celular.Text <> ´( ) - ´ Then
SQL_Clientes.SQL.ADD(´ ,´´+ME_Celular.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Edit_IEstadual.Text+´´ ´);
If ME_CNPJ.Text <> ´ . . / - ´ Then
SQL_Clientes.SQL.ADD(´ ,´´+ME_CNPJ.Text+´´ ´);
IF ME_CPF.Text <> ´ . . - ´ Then
SQL_Clientes.SQL.ADD(´ ,´´+ME_CPF.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Memo_Observacao.Text+´´) ´);
SQL_Clientes.Prepare;
SQL_Clientes.ExecSQL;
SQL_Clientes.SQL.CLEAR;[/color:4200d4177f]

vonirpereira@certto.com.br


Responder

Gostei + 0

03/04/2003

Anonymous

[quote:96e49a7e58=´José´]Olá pessoal, Estou trabalhando com o SQL 7.0 e Delphi 5. Tenho umas tabelas que são muito grandes e estou pensando em deixar de utilizar o TTable e passar a usar TQuery. Como faço para salvar as alterações efetuadas na consulta direto no banco de dados ? Esta forma de trabalhar é segura ? Grato, José


Siga o exemplo que dara certo

[color=blue:96e49a7e58] SQL_Clientes.Close;
SQL_Clientes.Sql.Clear;
SQL_Clientes.SQL.ADD(´ INSERT INTO Clientes ´);
SQL_Clientes.SQL.ADD(´ (Cod_Cliente´);
SQL_Clientes.SQL.ADD(´ ,Cliente´);
SQL_Clientes.SQL.ADD(´ ,Endereco´);
SQL_Clientes.SQL.ADD(´ ,Municipio´);
SQL_Clientes.SQL.ADD(´ ,Bairro´);
If ME_DataCad.Text <> (´ / / ´) Then
SQL_Clientes.SQL.ADD(´ ,DataCad´);
SQL_Clientes.SQL.ADD(´ ,Cep´);
SQL_Clientes.SQL.ADD(´ ,UF´);
If ME_Fone.Text <> ´ ( XX ) - ´ Then
SQL_Clientes.SQL.ADD(´ ,Fone´);
If ME_Celular.Text <> ´( ) - ´ Then
SQL_Clientes.SQL.ADD(´ ,Celular´);
SQL_Clientes.SQL.ADD(´ ,InsEst´);
If ME_CNPJ.Text <> ´ . . / - ´ Then
SQL_Clientes.SQL.ADD(´ ,CNPJ´);
IF ME_CPF.Text <> ´ . . - ´ Then
SQL_Clientes.SQL.ADD(´ ,CPF´);
SQL_Clientes.SQL.ADD(´ ,Obs) ´);

SQL_Clientes.SQL.ADD(´ VALUES (´´+IntToStr(CodigoCliente)+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Edit_Cliente.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Edit_Endereco.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Edit_Municipio.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Edit_Bairro.Text+´´ ´);
If ME_DataCad.Text <> (´ / / ´) Then
SQL_Clientes.SQL.ADD(´ ,´´+FORMATDATETIME(´mm/dd/yyyy´, StrToDate(ME_DataCad.Text))+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Edit_Cep.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Edit_UF.Text+´´ ´);
If ME_Fone.Text <> ´ ( XX ) - ´ Then
SQL_Clientes.SQL.ADD(´ ,´´+ME_Fone.Text+´´ ´);
If ME_Celular.Text <> ´( ) - ´ Then
SQL_Clientes.SQL.ADD(´ ,´´+ME_Celular.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Edit_IEstadual.Text+´´ ´);
If ME_CNPJ.Text <> ´ . . / - ´ Then
SQL_Clientes.SQL.ADD(´ ,´´+ME_CNPJ.Text+´´ ´);
IF ME_CPF.Text <> ´ . . - ´ Then
SQL_Clientes.SQL.ADD(´ ,´´+ME_CPF.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,´´+Memo_Observacao.Text+´´) ´);
SQL_Clientes.Prepare;
SQL_Clientes.ExecSQL;
SQL_Clientes.SQL.CLEAR;[/color:96e49a7e58]


se for alteração faça da seguinte forma:
[color=green:96e49a7e58] SQL_Clientes.CLOSE;
SQL_Clientes.SQL.CLEAR;
SQL_Clientes.SQL.ADD(´ UPDATE Clientes ´);
SQL_Clientes.SQL.ADD(´ SET Cliente = ´´+Edit_Cliente.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,Endereco = ´´+Edit_Endereco.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,Municipio = ´´+Edit_Municipio.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,Bairro = ´´+Edit_Bairro.Text+´´ ´);
If ME_DataCad.Text <> (´ / / ´) Then
SQL_Clientes.SQL.ADD(´ ,DataCad = ´´+FORMATDATETIME(´mm/dd/yyyy´, StrToDate(ME_DataCad.Text))+´´ ´);
SQL_Clientes.SQL.ADD(´ ,Cep = ´´+Edit_Cep.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,UF = ´´+Edit_UF.Text+´´ ´);
If ME_Fone.Text <> ´ ( XX ) - ´ Then
SQL_Clientes.SQL.ADD(´ ,Fone = ´´+ME_Fone.Text+´´ ´);
If ME_Celular.Text <> ´( ) - ´ Then
SQL_Clientes.SQL.ADD(´ ,Celular = ´´+ME_Celular.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,InsEst = ´´+Edit_IEstadual.Text+´´ ´);
If ME_CNPJ.Text <> ´ . . / - ´ Then
SQL_Clientes.SQL.ADD(´ ,CNPJ = ´´+ME_CNPJ.Text+´´ ´);
IF ME_CPF.Text <> ´ . . - ´ Then
SQL_Clientes.SQL.ADD(´ ,CPF = ´´+ME_CPF.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ ,Obs = ´´+Memo_Observacao.Text+´´ ´);
SQL_Clientes.SQL.ADD(´ WHERE Cod_Cliente = ´´+Label_Codigo.Caption+´´ ´);
SQL_Clientes.Prepare;
SQL_Clientes.EXECSQL;[/color:96e49a7e58]
vonirpereira@certto.com.br[/quote:96e49a7e58]


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar