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 » Simple U++ Sql Tutorial
Re: Simple U++ Sql Tutorial [message #9425 is a reply to message #9423] Mon, 07 May 2007 15:14 Go to previous messageGo to previous message
michael is currently offline  michael
Messages: 153
Registered: May 2007
Location: Germany
Experienced Member
fallingdutch wrote on Mon, 07 May 2007 08:15

did you add the Packages MySql and CtrlLib to your Application?

Bas


Hi Bas,

Yes, those packages were already added to my project.

But i've now realized my requirements like this:

I've added this packages to my application:
MySql
Sql
SqlCtrl


Added this to my header-file:
#include <SqlCtrl/SqlCtrl.h>
#include <MySQL/MySQL.h>


Added this to my constructor:
MySqlSession session;


And this is how i make my queries:
#include "prohibisZA.h"

void prohibisZA::ConnectMySQL()
{
	if(!session.Connect("prohibisZA", "password", "prohibisZA", "localhost"))
	{
    	PromptOK("Verbindungsaufbau zur Datenbank fehlgeschlagen!");
    }
}

void prohibisZA::SelectData(String sqlWhat, String sqlTable, String sqlWhere, String sqlOrder)
{
	Sql sql(session);
	sql.Execute("SELECT " + sqlWhat + " FROM " + sqlTable + sqlWhere + sqlOrder);
	while(sql.Fetch())
	{
		if(sqlTable == "prohibisZA_Kunden") {
			datagrid.Add(String(sql[1]), IntStr(sql[2]), IntStr(sql[3]), String(sql[4]), String(sql[5]), String(sql[6]));
		}
		else if(sqlTable == "prohibisZA_Server") {
			datagrid.Add(IntStr(sql[1]), String(sql[2]), String(sql[3]), String(sql[4]), String(sql[5]), String(sql[6]), String(sql[7]), String(sql[8]));
		}
	}	
}


Works good for me.

But what about the session? Now with this code i always create a new session for every query. Is this the right way?

Michael

[Updated on: Mon, 07 May 2007 15:14]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: small patch for PostgreSQL
Next Topic: Sql::Execute()
Goto Forum:
  


Current Time: Mon May 13 01:22:49 CEST 2024

Total time taken to generate the page: 0.01385 seconds