🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.database.multi-tier
1 messages
1 total messages Started by Guest Sun, 31 Dec 2000 01:49
Passing a value from a function to a SQL Query statement.
#902
Author: Guest
Date: Sun, 31 Dec 2000 01:49
103 lines
3696 bytes
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    ----------------------------------/
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads