Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » How to display fields from different tables in one SQLArray
Re: How to display fields from different tables in one SQLArray [message #19152 is a reply to message #19120] Sat, 15 November 2008 15:02 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13976
Registered: November 2005
Ultimate Member
sergeynikitin wrote on Thu, 13 November 2008 05:26


What do you mean? What is the difference between SQL and sql?



I mean that SQL is global variable (well, technically, it is more comlicated, but it behaves just like global variable).

And the inherent problem with global variables is that they are problem in reentrant code.

void Sum(int id) {
  return SQL % Select(SqlSum(MONEY)).From(TABLE).Where(ID == id);
}

void PrintSums() {
  SQL * Select(NAME, MONEY_ID).From(TABLE);
  while(SQL.Fetch())
     Print(SQL[NAME], Sum(SQL[MONEY_ID]);
}


I have made this bug way too many times -> that is why I always have to warn about fetching from SQL.

Quote:


	MySqlSession session;
	if(!session.Connect(app.mysql_username, app.mysql_password, app.mysql_database, app.mysql_server)) {
		printf("Can't connect with MySql\n");
		PromptOK(t_("Can't connect with MySql"));
		return;
	}
	mysql_set_character_set(session, "utf8");
	
	SQL = session;
	Sql sql(session);




This corrent and in fact, you do not need to repeat

Sql sql(session);

because

Sql sql;

is the same as

Sql sql(SQL.GetSession());

There are two purposes for SQL - to serve as simple cursor for inster/delete/update and inline fetches AND to represent default global database connection so that you do not need to repeat 'session' all the time.

Just do not do explicit fetches from it, because while technically possible, it is a sure way how to shoot you leg:)

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: DBF crash error while writing record
Next Topic: PATCH/BUGFIX Oracle asTable Failure - Solution
Goto Forum:
  


Current Time: Sat May 11 07:34:18 CEST 2024

Total time taken to generate the page: 0.03588 seconds