Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 06-20-2012, 06:41 PM
Ouiji Ouiji is offline
Senior Member
 
Join Date: Nov 2001
Location: US of A
Posts: 478
Send a message via AIM to Ouiji
Unhappy Problems writing to MySQL DB With Zeos

For whatever reason, my mind is blank and I cannot for the life of me figure out how to write data into the DB, while getting it out took me 5 seconds.

This is the code I am using to pull the data out of the database:

Code:
  zrQuery.SQL.Text := 'SELECT * FROM Event_Errors';
  zrQuery.Open();
  zrQuery.First();
  while not zrQuery.Eof do
  begin

   CurRow := grid_main.AddRow;
   Form1.grid_main.CellByName['e_ID', 'Last'].AsString        := zrQuery.FieldByName('Event_ID').AsString;
   Form1.grid_main.CellByName['e_OutPut', 'Last'].AsString    := zrQuery.FieldByName('Event_Output').AsString;
   Form1.grid_main.CellByName['e_Summary', 'Last'].AsString   := zrQuery.FieldByName('Summary').AsString;
   Form1.grid_main.CellByName['e_Severity', 'Last'].AsInteger := zrQuery.FieldByName('Severity').AsInteger;
   Form1.grid_main.CellByName['e_relations', 'Last'].AsString := zrQuery.FieldByName('Relations').AsString;
   Form1.grid_main.CellByName['e_KeyWords', 'Last'].AsString  := zrQuery.FieldByName('Keywords').AsString;
   Form1.grid_main.CellByName['e_Notes', 'Last'].AsString     := zrQuery.FieldByName('Notes').AsString;
   Form1.grid_main.BestFitRow(CurRow);

   zrQuery.Next();
  end;
  zrQuery.Close();

  sMemo1.Lines.Add('Query Complete');
This pulls the data from the table and puts it into a grid without any problems, but I cannot figure out how I would go about doing the reverse and inserting data into the table. Anyone have any ideas?

(I put this under General and not VCL because I think this is more of a lack of brain power than a question regarding zeos)

Thanks,
- ouiji
__________________
"not quite smart enough to be dumb"
Extended Stats No Longer Available Due To Changes To The Forum.
Reply With Quote
  #2  
Old 08-16-2012, 07:10 PM
emailx45 emailx45 is offline
Junior Member
 
Join Date: May 2012
Posts: 18
Default

Dear friend

All ACTION in database SQL (Firebird, MySql, SQL Server, Oracle, etc...) working in level of TRANSACTION.

So, YOU have open one Transaction for Insert, Update and Delete any record in table.

Example inserting data:

...
ComponentTransaction.StartTransaction;
... actions for insert data
Table1.append;
Table1.Fields[0].asString := 'text free';
Table1.Post;
ComponentTransaction.COMMIT; // for save data in database

...

Go to www.devrace.com and see the FIBPlus components (its great and fast = my preference heheehe). See the FAQs for TRANSACTION USE, etc...
Reply With Quote
  #3  
Old 08-16-2012, 09:18 PM
GeoWink GeoWink is offline
Senior Member
 
Join Date: Jan 2001
Posts: 785
Default

You can use the Query...

with YourQuery do
begin
Insert;
FieldByName('Field1').asString := String1;
FieldByName('Field2').asString := String1;
FieldByName('Field3').asInteger := Integer1;
Post;
end;

George
Reply With Quote
  #4  
Old 08-20-2012, 10:31 PM
Ouiji Ouiji is offline
Senior Member
 
Join Date: Nov 2001
Location: US of A
Posts: 478
Send a message via AIM to Ouiji
Default Thank You

I have been able to make it function, but the code is about as ugly as it gets. (No reference to your posts, only to my lack of wrapping my head around how a DataSet and Query worked. But thank you very much for the input.

- ouiji
__________________
"not quite smart enough to be dumb"
Extended Stats No Longer Available Due To Changes To The Forum.
Reply With Quote
  #5  
Old 08-21-2012, 05:25 AM
jamiguel77 jamiguel77 is offline
Senior Member
 
Join Date: Jan 2002
Posts: 1,138
Send a message via MSN to jamiguel77 Send a message via Yahoo to jamiguel77
Default

Ouiji

contact me via skype i can help you (my skype id is: jamiguel77)

i have so so 10 years working with zeos, but why you dont use standard sql?

query1.sql.text:='insert into my table( ....)';


thanks
Reply With Quote
  #6  
Old 08-22-2012, 12:33 AM
Ouiji Ouiji is offline
Senior Member
 
Join Date: Nov 2001
Location: US of A
Posts: 478
Send a message via AIM to Ouiji
Smile Thank you for the kind offer, You will know my skype name from my forum name =)

This is the code I came up with, it just feels dirty to me, and I need to use it too input large amounts of data, so it feels like it would be unreliable. but that could just be my lack of experience with Zeos.


Code:
var
Data:Array [1..7] of String;
mQRY:String;
begin

 sMemo1.Lines.Add('Attempting to Write Event to DB..');

 data[1] := edt_eID.Text;
 data[2] := edt_eOutp.Text;
 data[3] := edt_sum.Text;
 data[4] := edt_Sev.Text;
 data[5] := edt_rel.Text;
 data[6] := edt_kw.Text;
 data[7] := memo_Notes.Lines.Text;

 mQRY := ('INSERT INTO Event_Dev (Event_ID, Event_Output , Summary , Severity , Relations , Keywords , Notes)' +
                                                                                           ' VALUES(' + #39 + data[1] + #39 + #44 +
                                                                                                        #39 + data[2] + #39 + #44 +
                                                                                                        #39 + data[3] + #39 + #44 +
                                                                                                        #39 + data[4] + #39 + #44 +
                                                                                                        #39 + data[5] + #39 + #44 +
                                                                                                        #39 + data[6] + #39 + #44 +
(* End of Statment *)                                                                                   #39 + data[7] + #39 + ')' );

 if zCon.ExecuteDirect(mQRY) then
  sMemo1.Lines.Add('Query Success.')
   else sMemo1.Lines.Add('Query Failed.');
Does this seem like it could be workable? So far it has done the job, but it has not really been "stress tested" in a real life situation. I am anxious to hear your thoughts.
__________________
"not quite smart enough to be dumb"
Extended Stats No Longer Available Due To Changes To The Forum.
Reply With Quote
  #7  
Old 08-22-2012, 02:59 PM
jamiguel77 jamiguel77 is offline
Senior Member
 
Join Date: Jan 2002
Posts: 1,138
Send a message via MSN to jamiguel77 Send a message via Yahoo to jamiguel77
Default

if you work with zeos and insert data, the problem not is Zeos is the Query or delphi language.

for insert an amount of data here is the way:

http://www.electrictoolbox.com/mysql...tiple-records/

i use mysql.

or, you rename your fields same as:

field01, field02, field03.....

wsql1:='';
wsql2:='';
for i:=0 to 90 do (i suppose you have 90 fields
begin
wsql1:=wsql1+'field'+formatfloat('00',i)+',';
wsql2:=wsql2+arraydata[i]+',';
end;

query1.sql.text:='Insert into mytable ('+copy(wsql1,1,length(wsql1)-2)+') valeus ('+copy(wsql2,1,length(wsql2)-2)+')'; //for remove the last ,
query1.execute;



here too i paste some code i write on any project
(i have much data on a text file.

if openD.execute then
begin
Assignfile(f,opend.filename);
reset(f);
readln(f,l);
for i:=0 to wnofields do //extract the fieldnames (are the header of the text file)
begin
wa1[i]:=copy(l,1,pos(#9,l)-1);
delete(l,1,pos(#9,l));
end;
k:=1;
while not eof(f) do
begin
readln(f,l);
caption:=inttostr(k)+' '+l;
application.ProcessMessages;
for i:=0 to wnofields do
begin
wa2[i]:=copy(l,1,pos(#9,l)-1);
delete(l,1,pos(#9,l));
end;
zq.sql.text:='Select * from tbit where ibitidgan='+inttostr(integer(cg.Items.objects[cg.itemindex]))+' and ibitidentif='+wa2[2]+' and '+
'ibitidnomcapt='+inttostr(integer(cr.Items.objects[cr.itemindex]));
Zq.open;
if Zq.IsEmpty then
begin
zq.sql.text:='Insert into tbit (ibitidentif, ibittipo, ibitarever, ibitnocarp, ibitnofac, ibitnocenso, cbitraza, cbitclave, cbitnomtit, '+
'cbitdomtit, cbitrantit, ibitareazu, ibitresenado, dbitfecresena, dbitfechregmod, dbitfechreg, cbitcorral, '+
'cbitTIPO, fbitkgs, cbitstatus, cbitquienentrego, cbitnodict, dbitfeiny, ibitedad, ibitedad2, ibitsexo, cbitmun, '+
'ibitidentif2, ibitareteverde, cbitresultado, ibitidgan, ibitidnomcapt) values (';
wx:='';
for i:=2 to wnofields do
begin
wx:=wx+''+inttostr(i)+', ';
end;
wx:=copy(wx,1,length(wx)-2);
zq.sql.text:=zq.sql.text+wx+', idbitgan, idbitnomcap )';
for i:=2 to wnofields do
begin
if i=30 then
caption:=caption;
case wa1[i][1] of
'i': begin
if not (wa2[i]='Null') then
zq.parambyname('p'+inttostr(i)).asinteger:=strtoin t(wa2[i])
else
zq.parambyname('p'+inttostr(i)).Clear;
end;
'f': begin
if not (wa2[i]='Null') then
zq.parambyname('p'+inttostr(i)).asfloat:=strtofloa t(wa2[i])
else
zq.parambyname('p'+inttostr(i)).Clear;
end;
'c': begin
if not (wa2[i]='Null') then
zq.parambyname('p'+inttostr(i)).asstring:=wa2[i]
else
zq.parambyname('p'+inttostr(i)).Clear;
end;
'd': begin
{ showmessage('0 '+Zq.SQL.text);
clipboard.astext:=Zq.SQL.text;}
if not (wa2[i]='Null') then
begin
//14/04/2012 06:27:53 p.m.
if ShortDateFormat='M/d/yyyy' then
zq.parambyname('p'+inttostr(i)).asdatetime:=strtod atetime(copy(wa2[i],4,2)+'/'+copy(wa2[i],1,2)+'/'+copy(wa2[i],7,4)+' '+copy(wa2[i],12,13))
else
zq.parambyname('p'+inttostr(i)).asdatetime:=strtod atetime(wa2[i])
end
else
zq.parambyname('p'+inttostr(i)).Clear;
end;
else
caption:=caption;
end;
end;
// showmessage('1 '+Zq.SQL.text);
zq.parambyname('pidbitgan').asinteger:=integer(cg. Items.objects[cg.itemindex]);
zq.parambyname('pidbitnomcap').asinteger:=integer( cr.Items.objects[CnombreResena.itemindex]);
// showmessage('2 '+Zq.SQL.text);
clipboard.astext:=Zq.SQL.text;
Zq.ExecSQL;
inc(k);
end
else
begin
{ messagedlg('El arete de Siniga: '+wa2[2]+' ya esta capturado!!! con fecha: '+formatdatetime('dd/mm/yyyy',
Zq.fieldbyname('dbitfecresena').asdatetime),mterro r, [mbok],0);}
Mem.Lines.add('El arete de Siniga: '+wa2[2]+' ya esta capturado!!! con fecha: '+formatdatetime('dd/mm/yyyy',
Zq.fieldbyname('dbitfecresena').asdatetime));
end;
end;
closefile(f);


is a pleasure help try help.


thanks
Reply With Quote
  #8  
Old 09-09-2012, 05:51 PM
emailx45 emailx45 is offline
Junior Member
 
Join Date: May 2012
Posts: 18
Thumbs up

Try, always, show the "new sql" query in one MEMO, SHOWMESSAGE, etc.. for verify the sintax correct, ok?
Reply With Quote
Reply

Tags
database, insert, mysql, table, zeos

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 10:01 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.