MyDAC and TMyQuery
MyDAC and TMyQuery
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!!
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!!
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:
Use MyConsulta->Next to scroll to the next record. For more information about using DataSets, read the Delphi Help documentation.
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
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
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
Please refer to this thread. Here you will find some examples on how to work with the BLOB fields in C++Builder.
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:
But it doesn't work. Neither using MyTablaPlantaplano->LoadFromFile("C:\temp.bmp"); ( field called plano --> image )
MyTablaPlanta->Post();
Somebody help me?
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();
MyTablaPlanta->Post();
Somebody help me?
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:
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
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();
MyTablaPlanta->Post();
Somebody help me?
This code was rigth, but doesn't work
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:
;
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.
( the value 1600000000 for example for me was enough ).
Now i can insert doing those two command. NO PROBLEMS NOW!!!
Regards![/code]
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 Now i can insert doing those two command. NO PROBLEMS NOW!!!
Regards![/code]