Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Passing a value from a function to a SQL Query statement.

Passing a value from a function to a SQL Query statement.

From: Edward Ascencio <cedwarda_at_altavista.com>
Date: Sat, 30 Dec 2000 17:56:07 -0800
Message-ID: <3a4e9319_2@news2.cwnet.com>

Hi, Guys when writting a cleint application if I perform a calculation from say two rows from two different tables from an SQL server and then have the result outputed back to table. How can I pass the variable from the function to sql statement in C++ here's my example .

/- C_C is Column from Client table
/- C_F is Column from Finance table
/- f_func is the math function to calculate the interest
/- V_ouputfrmfunc is the output from func
/- %C_C is the attribute variable which is assigned a value from the <
V_ouputfrmfunc >.
//--------------------------------------------------------------------/

#include <vcl.h>
#include <stdlib.h>
#include <iostream.h>
#include <math.h>
#include <stdlib.h>
#pragma hdrstop
//---------------------------------------------------------------------/

#pragma package(smart_init)
//-------------Connecting to a SQL Server -----------------//

Database1->AliasName ="oradb1";
Database1->DataBaseName ="Oracle SQL";

Database1->Params->Values["user name"] = "test1"; Database1->Params->Values["password"] = "test2" ;
/--------------End of Procedure ----------------------------------/


//-----------Create ODBC connection to Tables ----------------- //

TTable* table = new TTable(t_client);
table->DatabaseName = "oradb1"
table->TableName ="client";

TTable* table = new TTable(t_finance);
table->DatabaseName = "oradb1"
table->TableName ="finance";

/--------------End of Procedure ----------------------------------/




/------------extract string var from tables -------------/

string C_C = table->FieldByName('PRINCIPLE')->AsString + ","; {

double strtod(const char *C_C, char **endptr);

char C_C[80], endptr;

     double value;

     gets(C_C);
     value = strtod(C_C, &endptr);
     return 0;

string C_F = table->FieldByName('PERCENTAGE')->AsString + ","; {

double strtod(const char *C_F, char **endptr);

char C_F[80], endptr;

     double value;

     gets(C_F);
     value = strtod(C_F, &endptr);
     return 0;

}

while

/---use atof to convert string to a float -------------/

func f_func(double C_C, double C_F);
{

( C_C * C_F) + C_C

};

/ * %C_C --- is the a place holder for a variable "result from function mention above"/
/* "V_ouputfrmfunc" Is the actual value from the function.

/--------------- execu sql ------------------------------/


Query1->sql->Clear();
Query1->sql->Add("UPDATE client")
Query1->sql->Add("SET CLOSINGB = <%C_C>, V_ouputfrmfunc ")          /*  <
how can pass a value from a function return value to query statement ? */ Query1->sql->Add("WHERE 'job' = 'ACCOUNTNUM'; ") Query1->sql->ExecSQL();
/-------------- End SQL    ----------------------------------/
Received on Sat Dec 30 2000 - 19:56:07 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US