how to use bind variables from derived class (sqlvarsetup)

forum.td.development (2005-2010)
Marco Westermann

how to use bind variables from derived class (sqlvarsetup)

Post by Marco Westermann » 10 Mar 2010, 13:08

 Posted by:  Marco Westermann 

Hi,

I have an issue with bind variables which doesn't work. I have the
following:

TD 2005.1 / SQLBase 9.1

In a base class called CDbTable I have a function persist()
this function does a connect, prepares a insert-statement and executes
it. The problem is, that the bind variables comes from a derived class.

the documentation of the function SqlVarSetup says:

Use this function to write:
A hierarchy of classes where a base class can prepare and fetch and a
derived class can specify the into variables.

But the call to this function between prepare and execute doesn't work
neither, maybe because it only works with into-variables not with
bind-variables? Is there a way to solve my problem? It would help a lot.

Thanks so far,

Marco Westermann

Rainer Ebert

how to use bind variables from derived class (sqlvarsetup)

Post by Rainer Ebert » 10 Mar 2010, 16:09

 Posted by:  Rainer Ebert 

Never used SqlVarSetup.

But have you tried to implement a late bound funtion call in the base class
which calls a function of the derived class?

Regards,
Rainer

Marco Westermann

how to use bind variables from derived class (sqlvarsetup)

Post by Marco Westermann » 10 Mar 2010, 16:20

 Posted by:  Marco Westermann 

Hi Rainer,

yes, that would be a possibility. The problem is, every derived class
from CDbTable then must have this function implemented (with exactly the
same code). That is why I want to do it in the base class.

Marco

Rainer Ebert

how to use bind variables from derived class (sqlvarsetup)

Post by Rainer Ebert » 10 Mar 2010, 17:09

 Posted by:  Rainer Ebert 

Hi Marco,

if the code is exactly the same, why don't you define the bind variable(s)
in the base class?

Regards,
Rainer

Marco Westermann

how to use bind variables from derived class (sqlvarsetup)

Post by Marco Westermann » 10 Mar 2010, 17:43

 Posted by:  Marco Westermann 

:-) cause the bind variables are not the same. every class derived from
CDBTable must have a function which provides the information about the
class itself, which is called latebound from the persist-function in
CDbTable. so the persist-function stays the same even the sql-command
differs. here is a short code snippit to make it clear:

My target is to create a unified structure of classes each represanting
a database table.

http://pastebin.com/DwFfZfqT

thanks, Marco

Stefan Beltrame

how to use bind variables from derived class (sqlvarsetup)

Post by Stefan Beltrame » 10 Mar 2010, 21:34

 Posted by:  Stefan Beltrame 

Hi Marco

There are comming to approaches in my mind:

1) call SqlVarSetup in your class as late bind.

class CDBTable
...
Call SqlPrepare(hSql, sCommand)
Call ..varSetup(hSql)
Call SqlExecute(hSql)
...

class DepartmentTable
...
Function: varSetup
Description:
Returns
Boolean:
Parameters
Sql Handle: phSql
Static Variables
Local variables
Actions
Return SqlVarSetup(phSql)
..

2) use SalCompileAndEvalute with context of class

ihSql must be an instance (or class) variable in CDBTable. Or even a global
variable.
Because it must be in the scope of the derived class.

class CDBTable
...
Call SqlPrepare(ihSql, sCommand)
Call SalCompileAndEvaluate('SqlVarSetup(ihSql)', nError, nErrorPos, nReturn,
sReturn, dtReturn, hReturn, FALSE, ..getContextCurrent())
Call SqlExecute(ihSql)
...

class DepartmentTable
...
Function: getContextCurrent
Description:
Returns
String:
Parameters
Static Variables
Local variables
Actions
Return SalContextCurrent()
...

Regards
Stefan

Marco Westermann

how to use bind variables from derived class (sqlvarsetup)

Post by Marco Westermann » 10 Mar 2010, 23:58

 Posted by:  Marco Westermann 

Hi Stefan,

thank you a lot. It works.. this is great.

I attached a very simple sample for all who are interested in how this
works.
First, run the sql-skript on a database of your choise.
Second, configure the database-parameters in App_Startup Message of the
application.

Thanks again, Stefan,

regards, Marco

Attachment: dbTable-Test.zip

Return to “td.development”

Who is online

Users browsing this forum: [Ccbot] and 0 guests