(First, in portuguese, my mother tongue. Later in English.)

Olá Felipe,

Obrigado pela ajuda.

Na verdade eu já tinha lido estes tutoriais. Inclusive o de um demo de MySQL que usa os componentes Sqldb que é de uso similar para o Postgre.

O problema é que só há exemplos de uso de "select" para fins de exibição e navegação de dados em forms com dbedits, dbnavigator, etc. Não há exemplo mostrando o uso do "update" ou "insert" de dados com o uso destes controles. Quando você edita e salva um registro com o dbnavigator, datasource, ele apenas fica salvo (se é que fica) na memória (em cache). Porém, por exemplo, no Delphi, usando o TClienteDataset, você daria um "applyupdates" no evento "afterpost" para que o cache fosse gravado no banco. Com o uso dos componentes Sqldb (TPQConnection, TSQLQuery, TSQLTransaction) eu não pude fazer isso. Entretanto, eu vi num fórum o seguinte exemplo:

"begin
 { The SQLQuery in Lazarus does work with parameters yet, so }
 { we build the SQL statement completely.                      }
 SQLQuery2.SQL.Text := ' update CUSTOMER set'#10 +
' CUSTOMER = ''' + LabeledEdit2.Text + ''','#10 + ' CONTACT_FIRST = ''' + LabeledEdit3.Text + ''','#10 + ' CONTACT_LAST = ''' + LabeledEdit4.Text + ''','#10 + ' PHONE_NO = ''' + LabeledEdit5.Text + ''','#10 + ' ADDRESS_LINE1 = ''' + LabeledEdit6.Text + ''','#10 + ' ADDRESS_LINE2 = ''' + LabeledEdit7.Text + ''','#10 + ' CITY = ''' + LabeledEdit8.Text + ''','#10 + ' STATE_PROVINCE = ''' + LabeledEdit9.Text + ''','#10 + ' POSTAL_CODE = ''' + LabeledEdit11.Text + ''','#10 + ' COUNTRY = ''' + LabeledEdit10.Text + ''''#10 +
                       ' where CUST_NO = '  + LabeledEdit1.Text;
 SQLQuery2.ExecSQL;
 TSQLTransaction(SQLQuery2.Transaction).Commit;
end;"

Veja este outro exemplo logo abaixo:

"Don't use DBAware components. In Delphi I always build specific forms for data entry and use plain edit-boxes to display the data to the user. When data needs to be entered use an SQL-statement with parameters like:


 SQL.Text := 'UPDATE MyTable ' +
             'SET ' +
             'Field1 = :Field1 ' +
             'Field2 = :Field2 ' +
             'WHERE ' +
             'IdField = :IdField';

Then it is just a matter of assigning the texts from the EditBoxes to the values of the parameters and call ExecSQL."

Porém este segundo exemplo parece não ser possível, pois no comentário do primeiro exemplo o autor diz que o componente SQLQquery ainda não aceita parâmetros. Por isso ele teve que montar completamente a string sql usando diretamente os Edits.

Eu sempre montava as strings sql quando usava o Delphi em aplicações de responsabilidade, controlando as transações e tratando exceções. Porém em aplicações simples, gostaria de poder atualizar os campos diretamente usando os componentes DBAware, mas acho que não é possível com o pacote Sqldb. Pois, é o que diz o autor do segundo exemplo. A recomendação é a de não usar diretamente os componentes visuais DBAware para atualizar os dados no banco, uma vez que não é possível.

Então, gostaria que você me enviasse o seu exemplo usando o SQLLite para eu poder dar uma olhada.

Obrigado.
======== x ========
(in english version)

Olá Felipe, thank you for your help me and excuse-me for my bad English.

In the truth I already had read these tutorials. Also I look a demon of MySQL that uses Sqldb components that are of similar use for the Postgre.

The problem is that these examples use "select" for ends of exhibition and navigation of data in forms with dbedits, dbnavigator, etc. The "update" or "insert" use with DbAware controls does not have example showing. When you edit and write a register using dbnavigator, datasource, it is written in the ram memory (in cache). However, for example, in the Delphi, using TClienteDataset, you write (commit) with "applyupdates" in the event "afterpost", so that cache is recorded in database. Using Sqldb components (TPQConnection, TSQLQuery, TSQLTransaction) I can't make this. However, I saw in web forum the following example:

"begin
 { The SQLQuery in Lazarus does work with parameters yet, so }
 { we build the SQL statement completely.                      }
 SQLQuery2.SQL.Text := ' update CUSTOMER set'#10 +
' CUSTOMER = ''' + LabeledEdit2.Text + ''','#10 + ' CONTACT_FIRST = ''' + LabeledEdit3.Text + ''','#10 + ' CONTACT_LAST = ''' + LabeledEdit4.Text + ''','#10 + ' PHONE_NO = ''' + LabeledEdit5.Text + ''','#10 + ' ADDRESS_LINE1 = ''' + LabeledEdit6.Text + ''','#10 + ' ADDRESS_LINE2 = ''' + LabeledEdit7.Text + ''','#10 + ' CITY = ''' + LabeledEdit8.Text + ''','#10 + ' STATE_PROVINCE = ''' + LabeledEdit9.Text + ''','#10 + ' POSTAL_CODE = ''' + LabeledEdit11.Text + ''','#10 + ' COUNTRY = ''' + LabeledEdit10.Text + ''''#10 +
                       ' where CUST_NO = '  + LabeledEdit1.Text;
 SQLQuery2.ExecSQL;
 TSQLTransaction(SQLQuery2.Transaction).Commit;
end;"

Look below the next example:

"Don't use DBAware components. In Delphi I always build specific forms for data entry and use plain edit-boxes to display the data to the user. When data needs to be entered use an SQL-statement with parameters like:


 SQL.Text := 'UPDATE MyTable ' +
             'SET ' +
             'Field1 = :Field1 ' +
             'Field2 = :Field2 ' +
             'WHERE ' +
             'IdField = :IdField';

Then it is just a matter of assigning the texts from the EditBoxes to the values of the parameters and call ExecSQL."

However this as example seems not to be possible, therefore in the commentary of the first example the author says that SQLQquery component still don't accepts parameters. Therefore he mounted the sql string with "Edit.text". In Delphi, I always mounted strings sql, controlling the transactions and treating exceptions. However, in very simple applications, I would like to be able to update the fields using the DBAware components, but I see that it is not possible with Sqldb. Therefore, the second author says this. The recommendation is not to use directly the visual components DBAware to update the database.

So, I would like that you sent me your SQLLite example.

Thanks,

Paulo

----- Original Message ----- From: "Felipe Monteiro de Carvalho" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Saturday, December 03, 2005 11:45 AM
Subject: [lazarus] Re: About PSQL (Sqldb package) Components


Prof. Paulo Amaral wrote:
I am tired of being using illegal passenger of windows.  Therefore I am
migrando for the Linux.  However, for that I see, she is this well the
reception that I receive, instead of being received in the group. So, Do I
must come back and applaud Bill Gates or to join me the Linus Torvalds?

Would you like apple pie as well?

This is what I would can "an unfortunate joke". I bet it wasn't meant to
be aggressive, but perhaps was misplaced.

I welcome you to Linux, Lazarus and this newsgroup.

Now, going back to the task at hand.

> Also, if you have examples with sqldb component packge or other,
please, send me.

Have you already successfully created a Lazarus Database Application
that conects to a simple database like DBase or SQLite? This is the
first step, then you can go for PostgreSQL.

The most basic component is TDbf and is the best documented one. You can
find it´s tutorial here:
http://wiki.lazarus.freepascal.org/index.php/Lazarus_Tdbf_Tutorial

I recommend that you create first a program that uses TDbf and then
switch to Postgre.

The data-aware components represent fields and are connected by the
correct setting of properties to a TDataSource, witch represents a table
and is also connected to the database components, be it TPSQLDatabase,
TSQLiteDataSet or something else.

So if you create a database program with TDbf and wish to change to
another database system you only need to delete the TDbf component you
dropped on the form, drop a new database component and change the
property on the DataSource to point to the new database system.

> Is it possible to update postgresql tables with dbcontrols
(datasource, dbnavigator, dbedit...) ?

Yes, that is what the components are made for.

Did you try looking at the wiki? It is located here:
http://wiki.lazarus.freepascal.org/index.php/Lazarus_Database_Tutorial

Do you have difficulty understanding english? I can write for you in
portuguese (suposing this is your mother tongue).

I do have a database program and can send you. It works with SQLite. The
comments are in portuguese. Is it ok for you? I just have to take a look
at it to make sure it works before sending it.

thanks,

Felipe

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives




--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.11/191 - Release Date: 2/12/2005


_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to