Home > Back-end >  Consult the Delphi call mysql stored procedures
Consult the Delphi call mysql stored procedures

Time:09-15

Himself with delphi7 TADOStoredProc invoke mysql stored procedures, the stored procedure does not require the incoming parameters, smooth access to return data sets,
the stored procedure code is as follows:
The CREATE DEFINER=` root ` @ ` localhost ` PROCEDURE ` test ` ()
The begin
DECLARE GoodsID int the default 0;
DECLARE no_more_products, quantity_in_stock INT the DEFAULT 0;
DECLARE cur_product CURSOR FOR the select distinct goods_id from ecs_order_goods;
DECLARE the CONTINUE HANDLER FOR the NOT FOUND SET no_more_products=1;

Drop table if the exists tmptable;
Create TEMPORARY table tmptable
(
ID INT (11) the NOT NULL AUTO_INCREMENT,
StrInfo varchar (1000),
StrTotal varchar (500),
Primary key (ID)
);

The OPEN cur_product;
The fetch cur_product into GoodsID;

REPEAT
INSERT INTO tmptable (strInfo) VALUES (' 123 ');

The fetch cur_product into GoodsID;
UNTIL no_more_products=1
END REPEAT;
The CLOSE cur_product;

SELECT * FROM tmptable;
DROP TABLE tmptable;
end;

Delphi calling code is as follows:
With spExec do
The begin
The Close;
ProcedureName:='ecs_test';
The Parameters. The Clear;
Prepared:=false;
//Parameters. CreateParameter (' iUserID, ftInteger, pdInput, 4, iRow);
Prepared:=true;
The Open;
.
The end;

Then I add incoming parameters in the process of statement, other content,
The CREATE DEFINER=` root ` @ ` localhost ` PROCEDURE ` test ` ( in iUserID int
The begin
./* all of the code remains the same, */
The end;

Delphi calling code to the following:
IRow:=1;
With spExec do
The begin
The Close;
ProcedureName:='test';
The Parameters. The Clear;
Prepared:=false;
The Parameters. CreateParameter (' iUserID, ftInteger, pdInput, 4, iRow);
Prepared:=true;
The Open;
.
The end;
The correct result is executed, as shown in the figure:


if delete the content of the stored procedure at this time, just add a select statement to return a set of data, and there is no problem, that parameter is introduced into should be yes,

Please guide you got talent, thank you!

CodePudding user response:

 
With spExec do
The begin
The Close;
ProcedureName:='test';
Prepare;
ParamByName (" iUserID "). The Value:=4;//4 or iRow? Don't quite understand
//Parameters. CreateParameter (' iUserID, ftInteger, pdInput, 4, iRow);
The Open;
.
The end;

CodePudding user response:

 
With spExec do
The begin
The Close;
ProcedureName:='test';
Prepared:=True;
The Parameters. ParamByName (" iUserID "). The Value:=iRow;
//Parameters. CreateParameter (' iUserID, ftInteger, pdInput, 4, iRow);
The Open;
The end;

CodePudding user response:

I can't ~

CodePudding user response:

 
With spExec do
The begin
The Close;
ProcedureName:='test';
The Parameters. The Clear;
The Parameters. CreateParameter (' iUserID, ftInteger, pdInput, 4, iRow);
The Open;
The end;

CodePudding user response:

Ado is already very old stuff, it is recommended that the UniDAC instead, I found there are many people on the BBS still use BDE, ado such antiques, really confusing,

CodePudding user response:

Inertia, estimate that most developers use the Delphi 1/10 less than the ability of...

CodePudding user response:

 
//can also wrote
With spExec do
The begin
The Close;
TestProc ProcedureName:=' ';
The Parameters. Refresh;
The Parameters. ParamByName (' @ iUserID '). The Value:=iRow;
The Open;
The end;

CodePudding user response:

reference 5 floor BlueStorm reply:
ado is already very old stuff, suggest UniDAC instead, I found there are many people on the BBS still use BDE, ado such antiques, really confusing,

Application is not deep, like me, that is to write a few simple applications, for easy some departments work together, it is used to the simple ADO + MSSQL, too deep influence developed instead,
Try these days about fircedac, basically and ADO about, but a lot of different place could not be, online tutorials and rarely, decisively abandoned, ha ha

CodePudding user response:

Another key is my little three layer architecture, even don't have to store, is a connect to the database, reading and writing database, a table, backup, ha ha

CodePudding user response:

Want to simple can use sdac (for SQL server) and MyDac (MySql), can be directly connected database, don't need to drive, in terms of use is more simple than bde or ado,

Actually UniDAC is also relatively simple and can connect almost all types of database, and can be accessed by many database is tcpip direct (no need to drive), such as oracle, SQL server, MySQL, DBF,

I also think FireDAC seems too complicated, but familiar with no too big problems,

CodePudding user response:

Actually Delphi also provides another way of connection to connect to the database: DBExpress, also calculate is simple to use, but the trouble is, DBX drive (DLL), together with the program cannot compile it connected in an exe file,

CodePudding user response:

EMB not make FireDAC a universal to third-party components to set aside a certain living space, is not a technical problem

CodePudding user response:

Or something like some people, or Delphi's own thing, otherwise, one is wrong don't find solution, secondly, once the upgrade Delphi and third-party plug-in is not followed, it cry dead in the toilet, ha ha

CodePudding user response:

In FireDAC components (such as FDQuery) written on the basis of their own class, and according to the class definition (interface), the interface program to access the database only through the interface,
Define your own classes and interfaces (interface) to write in a unit, if you want to replace FireDAC with ADO, replace the unit class with written based on ADO class,
nullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related