Topic: SQl script

Hi , Please i need to understand how to enter an SQL script in My Visual Database

Re: SQl script

Hello.


You can use function SQLExecute to run SQL query, also you can get some value from database, example:


var
   s: string;
begin
   s := SQLExecute('SELECT firstname FROM tablename WHERE id=1');


function SQLQuery is more advanced, allows you to get data from database, example

var
    Results: TDataSet;
    s1, s2: string;
begin

    SQLQuery('SELECT fieldname1, fieldname2 FROM tablename', Results);

    while not Results.Eof do
    begin                              
        s1 := Results.FieldByName('fieldname1').asString;
        s2 := Results.FieldByName('fieldname2').asString;
        Results.Next;
    end;



Also you can use button with action "SQL query"

Dmitry.

Re: SQl script

I will probably be using Sqlite for some projects. I'm used to MySQL which has stored procedures and I want to use them extensively I think.

Is there a reasonable way to put SQL scripts and logic in either the database or something where I can sort of create a set of stored procedures and run them in MVD upon record update, or insert, or for validation.

Brand to to MVD so hopefully this is not a dumb question.

Re: SQl script

asawyer13 wrote:

I will probably be using Sqlite for some projects. I'm used to MySQL which has stored procedures and I want to use them extensively I think.

Is there a reasonable way to put SQL scripts and logic in either the database or something where I can sort of create a set of stored procedures and run them in MVD upon record update, or insert, or for validation.

Brand to to MVD so hopefully this is not a dumb question.

MVD does not have special interface to manage stored procedures, so you should use free tools like MySQL Workbench or HeidiSQL to create stored procedures.


Example

CREATE DEFINER=`root`@`localhost` PROCEDURE `test`()
BEGIN
SELECT 'Hello';
END


How to call

procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
var
    s: string;
begin
    s := SQLExecute('call test();');
    ShowMessage(s);
end;

Also you can call procedures using button with action "SQL Query"

Dmitry.

Re: SQl script

DriveSoft wrote:

Also you can call procedures using button with action "SQL Query"

Could someone comment more on that? How do you call a procedure using a button with action "SQL Query"??

Re: SQl script

At the end of this post, Dmitry talks about stored procedures in MYSQL.
The MYSQL stored procedure can also be called using the button with the "SQL Query" function.
Unfortunately, MVD cannot create a stored function.