Embedded SQL

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Spag

Embedded SQL

Post by Spag » Fri 08 Apr 2005 15:19

I'm knocking up a program in Borland C++ Builder.

I'm trying to keep Database calls to a minimum to keep things fairly fast

MSSQL->SQL->Add("UPDATE student SET accessed = (accessed + 1) WHERE Code='" + Edit1->Text + "'" );
MSSQL->Execute();

But at this point I also want to retrieve a field, and return it to the user


I feel I want to do something like :

MSSQL->SQL->Add("UPDATE student SET accessed = (accessed + 1) WHERE Code='" + Edit1->Text + "' Score=:score" );
MSSQL->Execute();
ShowMessage(score);


any ideas anyone ?

Thanks - Spag

Spag

Right, I'm somewhere about here now but getting errors

Post by Spag » Fri 08 Apr 2005 15:53

MSSQL->SQL->Add("UPDATE student SET accessed = (accessed + 1) WHERE IN (SELECT Score INTO :Score FROM URLs WHERE Code='" + Edit1->Text + "' " );
MSSQL->Execute();

ShowMessage(MSSQL->ParamByName("Score")->AsString);

Spag

going round in circles

Post by Spag » Sat 09 Apr 2005 09:47

So Gave up trying to update the record at the same time and am just trying to retrieve a parameter. Got here, getting nothing in the ShowMessage box - though MSSQL->Params->Count is reporting that 1 parameter is returned.


MSSQL->SQL->Add("SET :Score= (SELECT Score FROM class WHERE student='" + Edit1->Text + "')");

MSSQL->Execute();

for(int i = 0 ; i Params->Count ; i++)
ShowMessage(MSSQL->Params->Items->AsString) ;


Anyone got any ideas ?

Spag

Oh I think I've sussed it

Post by Spag » Sun 10 Apr 2005 09:31

It was to do with pre-allocating the bind parameters or summut

Thanks
Spag

coool

...

Post by coool » Sun 10 Apr 2005 10:42

Maan this SDAC is soo cool - I love it

YaY

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Mon 11 Apr 2005 07:26

Try to set Param.ParamType = ptInputOutput

Spag

Yeah,

Post by Spag » Mon 11 Apr 2005 08:28

That's it entirely Ikar, you are right (as usual :) ).

But I went the whole hog and did :

MSSQL->Params->CreateParam(ftVariant, "Student", ptResult);
MSSQL->SQL->Add("SET :Student = (SELECT Student FROM Class WHERE (Code=123))");
MSSQL->Execute();
ShowMessage(MSSQL->Params-FindParam("Student")->AsString);

kinda

works, but dunno if it's the right way

Spag

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Mon 11 Apr 2005 11:00

You'd better use:

Code: Select all

 MSSQL->SQL->Add("SET :Student = (SELECT Student FROM Class WHERE (Code=123))");
 MSSQL->Params[0]->ParamType = ptInputOutput;
 MSSQL->Params[0]->DataType = ftInteger;
 MSSQL->Execute();
 ShowMessage(MSSQL->Params-FindParam("Student")->AsString);

Spag

Errors

Post by Spag » Mon 11 Apr 2005 12:19

Both the

MSSQL->Params[0]->ParamType = ptInputOutput;
MSSQL->Params[0]->DataType = ftString;

Generate :

[C++ Error] MForm.cpp(52): E2288 Pointer to structure required on left side of -> or ->*
[C++ Error] MForm.cpp(53): E2288 Pointer to structure required on left side of -> or ->*

Changing it to :

MSSQL->Params->Items[0]->ParamType = ptInputOutput;
MSSQL->Params->Items[0]->ParamType = ftString;

generates :

[C++ Warning] MForm.cpp(53): W8018 Assigning TFieldType to TParamType

in the second line.

dunno
Spag

Spag

My Mistake

Post by Spag » Mon 11 Apr 2005 12:25

MSSQL->Params->Items[0]->ParamType = ptInputOutput;
MSSQL->Params->Items[0]->ParamType = ftString;

Should be

MSSQL->Params->Items[0]->ParamType = ptInputOutput;
MSSQL->Params->Items[0]->DataType = ftString;

compiles perfectly then

:)

Spaggie

Yep,

Post by Spaggie » Mon 11 Apr 2005 12:29

Thats cool Ikar, what you said works great once I put the Params object in properly (Delphi/Builder VCL addressing differences)

So exactly what you suggested but :

MSSQL->SQL->Add("SET :Student = (SELECT Student FROM Class WHERE (Code=123))");
MSSQL->Params->Items[0]->ParamType = ptInputOutput;
MSSQL->Params->Items[0]->DataType = ftInteger;
MSSQL->Execute();
ShowMessage(MSSQL->Params-FindParam("Student")->AsString);


Lovely
Spag

Spag

Multiple return parameters

Post by Spag » Wed 25 May 2005 06:54

Code: Select all

MSSQL->SQL->Add("SET :Student = (SELECT Student FROM Class WHERE (Code=123))"); 
 MSSQL->Params[0]->ParamType = ptInputOutput; 
 MSSQL->Params[0]->DataType = ftInteger; 
 MSSQL->Execute(); 
 ShowMessage(MSSQL->Params-FindParam("Student")->AsString);
Hi,

Sorry to ask this but I cant work it out.

What's the syntax for multiple returns ?

Is it something along the lines of :

Code: Select all

MSSQL->SQL->Add("SET :Student :Course= (SELECT Student, Course FROM Class WHERE (Code=123))"); 
 MSSQL->Params[0]->ParamType = ptInputOutput; 
 MSSQL->Params[0]->DataType = ftInteger; 
 MSSQL->Params[1]->ParamType = ptInputOutput; 
 MSSQL->Params[1]->DataType = ftInteger; 
 MSSQL->Execute(); 
 ShowMessage(MSSQL->Params-FindParam("Student")->AsString);
Thanks
Spag

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Wed 25 May 2005 07:11

Code: Select all

MSSQL->SQL->Add("SET :Student= (SELECT Student FROM Class WHERE (Code=123));"); 
MSSQL->SQL->Add("SET :Course= (SELECT Course FROM Class WHERE (Code=123))"); 
Read MSDN for details

Spag

Thanks

Post by Spag » Wed 25 May 2005 12:40

Thanks Ikar

Post Reply