Page 1 of 1
MyDAC and TMyQuery
Posted: Tue 27 Feb 2007 22:05
by Ithilien
Hello,
i'm very noob using MyDac and MySQL. I'm trying to make a Query in C++ Builder. My code is the following:( trying to do one )
MyConsulta->Connection = MyConnection;
MyConsulta->SQL->Add("SELECT * FROM user");
MyConsulta->Active = true;
But now, i don“t know if the result of the query is on MyConsulta object, or i must asignate to an other object ( intuitiveli: vector ( of users ) = MyQuery->Execute() ).
If someone can help me i would be very pleased.
Thanks a lot!!
Posted: Thu 01 Mar 2007 08:55
by Antaeus
As a rule you should not assign query execution result to anything. After you open a query, you can access retrieved data using, for example, the FieldByName property. This may look like this:
Code: Select all
s = MyConsulta->FieldByName("string field")->AsString; // s is a string variable
n = MyConsulta->FieldByName("integer field")->AsInteger; // n is an integer variable
Use MyConsulta->Next to scroll to the next record. For more information about using DataSets, read the Delphi Help documentation.
Posted: Thu 01 Mar 2007 09:59
by Ithilien
That's right!!!!!
Thanks a lot, but now i have a new problem. I have a field having a photograph ( picture ) from the user. I created it using longblob, but now, i dont know how can i retrieve from the BD. Neither i know how to insert into BD using C++ Builder.
Can you explain me? And can you put an example to guide? I know that there are TImage Object, but if i use FieldByName, AsImage?? ( exists? )
Thanks
Posted: Fri 02 Mar 2007 12:26
by Antaeus
Please refer to
this thread. Here you will find some examples on how to work with the BLOB fields in C++Builder.
Posted: Sat 10 Mar 2007 17:44
by Ithilien
I can't do this:
i have to select a file ( jpg ) and i convert it to bmp without problems, but...i have to store it to DB. The SQL sentence i don't know how to do it.
My code is:
Code: Select all
insercion = "INSERT INTO planta (id_planta) VALUES("+ id + ")";
MyTablaPlanta->SQL->Clear();
MyTablaPlanta->SQL->Add(insercion);
MyTablaPlanta->ParamByName("blob")->LoadFromFile("C:\temp.bmp",ftBlob);
MyTablaPlanta->Execute();
But it doesn't work. Neither using MyTablaPlantaplano->LoadFromFile("C:\temp.bmp"); ( field called plano --> image )
MyTablaPlanta->Post();
Somebody help me?
Posted: Sat 10 Mar 2007 17:45
by Ithilien
I can't do this:
i have to select a file ( jpg ) and i convert it to bmp without problems, but...i have to store it to DB. The SQL sentence i don't know how to do it.
My code is:
Code: Select all
insercion = "INSERT INTO planta (id_planta) VALUES("+ id + ",:blob)";
MyTablaPlanta->SQL->Clear();
MyTablaPlanta->SQL->Add(insercion);
MyTablaPlanta->ParamByName("blob")->LoadFromFile("C:\temp.bmp",ftBlob);
MyTablaPlanta->Execute();
But it doesn't work. Neither using MyTablaPlantaplano->LoadFromFile("C:\temp.bmp"); ( field called plano --> image )
MyTablaPlanta->Post();
Somebody help me?
This code was rigth, but doesn't work
Posted: Mon 12 Mar 2007 07:50
by Antaeus
The code in your last post looks incorrect. You missed a BLOB field name in the INSERT statement. Only the id_planta field name appears. Please change your code and try again.
If this still does not work, please post the exact error message you get.
Posted: Mon 12 Mar 2007 19:01
by Ithilien
Yeah but, it doesn't work again.
I resolved problem:
"insercion" is an AnsiString variable. I tryed to insert from a a temp file created in bmp format doing that statement:
Code: Select all
insercion = insert into planta values("+id+",LOAD_FILE(C:\temp.bmp)"
;
But my application didn't insert the row. So, exploring the variable i saw that it was a conversion of the text because character \ is special. So i put C:\temp.bmp and the insert statement was quite successfully.
At this point, one more problem appeared: Maps ( .bmp ) so big cant insert into DB. So the enviroment variable max_allowed_packet must be modified.
Code: Select all
mysql> set max_allowed_packet = 1600000000
( the value 1600000000 for example for me was enough ).
Now i can insert doing those two command. NO PROBLEMS NOW!!!
Regards![/code]