|
|
Home » U++ Library support » U++ SQL » Simple U++ Sql Tutorial
Simple U++ Sql Tutorial [message #9408] |
Sat, 05 May 2007 17:39  |
 |
michael
Messages: 153 Registered: May 2007 Location: Germany
|
Experienced Member |
|
|
Hi there,
i'm very new to upp and i'm looking for a really simple tutorial how i can connect to an sql-db (best would be via odbc or directly to an ms-sql, maybe also to my-sql).
The SQLApp Example is a little bit to complicated for me at the moment. It would be very nice if someone could explain me a real basic upp-sql example.
Michael
Edit:
i have tried the Reference Example SQL MySQL and was not able to compile. I got the following error:
In file included from J:\Entwicklung\UPP\MySQL\MySQL.cpp:1:
C:/Programme/UltimatePP/uppsrc/MySql/MySql.h:12:19: MySql.h: No such file or directory
In file included from J:\Entwicklung\UPP\MySQL\MySQL.cpp:1:
C:/Programme/UltimatePP/uppsrc/MySql/MySql.h:44: error: ISO C++ forbids declaration of `MYSQL' with no type
C:/Programme/UltimatePP/uppsrc/MySql/MySql.h:44: error: expected `;' before '*' token
C:/Programme/UltimatePP/uppsrc/MySql/MySql.h:56: error: `MYSQL' has not been declared
C:/Programme/UltimatePP/uppsrc/MySql/MySql.h:50: error: `MYSQL_PORT' was not declared in this scope
C:/Programme/UltimatePP/uppsrc/MySql/MySql.h: In constructor `Upp::MySqlSession::MySqlSession()':
C:/Programme/UltimatePP/uppsrc/MySql/MySql.h:62: error: `mysql' undeclared (first use this function)
C:/Programme/UltimatePP/uppsrc/MySql/MySql.h:62: error: (Each undeclared identifier is reported only once for each function it appears in.
)
MySQL: 1 file(s) built in (0:01.93), 1935 msecs / file, duration = 3750 msecs, parallelization 96%
There were errors. (0:04.67)
Seems that there is something missing... what do i have to do to get this mysql-example work?
Michael
[Updated on: Sat, 05 May 2007 19:16] Report message to a moderator
|
|
|
|
|
|
|
|
Re: Simple U++ Sql Tutorial [message #9419 is a reply to message #9418] |
Sun, 06 May 2007 19:15   |
 |
michael
Messages: 153 Registered: May 2007 Location: Germany
|
Experienced Member |
|
|
Ok, found MySqlSchema and added this to my source-file:
#define SCHEMADIALECT <MySql/MySqlSchema.h>
#include "prohibisZA.h"
#include <Sql/sch_source.h>
and this to my header-file:
#define SCHEMADIALECT <MySql/MySqlSchema.h>
#define MODEL "prohibisZA.sch"
#include <Sql/sch_header.h>
but got these errors...
main.cpp
In file included from C:/Programme/UltimatePP/uppsrc/MySql/MySqlSchema.h:51,
from C:/Programme/UltimatePP/uppsrc/Sql/sch_header.h:35,
from J:\Entwicklung\UPP\prohibisZA\/prohibisZA.h:16,
from J:\Entwicklung\UPP\prohibisZA\mainmenu.cpp:7,
from C:/Programme/UltimatePP/out/prohibisZA/MINGW.Blitz.Gui.Main\$blitz.cpp:3:
C:/Programme/UltimatePP/uppsrc/Sql/sch_model.h:149:15: prohibisZA.sch: No such file or directory
C:/Programme/UltimatePP/uppsrc/GridCtrl/GridCtrl.h:916: warning: inline function `Upp::Item& Upp::GridCtrl::GetItem(int, int)' used but ne
ver defined
In file included from C:/Programme/UltimatePP/uppsrc/MySql/MySqlSchema.h:51,
from C:/Programme/UltimatePP/uppsrc/Sql/sch_header.h:35,
from J:\Entwicklung\UPP\prohibisZA\/prohibisZA.h:16,
from J:\Entwicklung\UPP\prohibisZA\main.cpp:9:
C:/Programme/UltimatePP/uppsrc/Sql/sch_model.h:149:15: prohibisZA.sch: No such file or directory
C:/Programme/UltimatePP/uppsrc/GridCtrl/GridCtrl.h:916: warning: inline function `Upp::Item& Upp::GridCtrl::GetItem(int, int)' used but ne
ver defined
prohibisZA: 4 file(s) built in (0:07.36), 1840 msecs / file, duration = 7609 msecs, parallelization 100%
There were errors. (0:08.82)
Any further ideas?
Michael
[Updated on: Sun, 06 May 2007 23:12] Report message to a moderator
|
|
|
|
Re: Simple U++ Sql Tutorial [message #9425 is a reply to message #9423] |
Mon, 07 May 2007 15:14   |
 |
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:
Added this to my header-file:
#include <SqlCtrl/SqlCtrl.h>
#include <MySQL/MySQL.h>
Added this to my constructor:
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
|
|
|
Re: Simple U++ Sql Tutorial [message #9427 is a reply to message #9425] |
Mon, 07 May 2007 15:45   |
|
datagrid.Add(String(sql[1]), IntStr(sql[2]), IntStr(sql[3]), String(sql[4]), String(sql[5]), String(sql[6]));
BTW, I suppose datagrid is an ArrayCtrl variable. There is no need to conver sql values to string type as arrayctrl can store different type values and display them properly. This line of code should rather look like:
datagrid.Add(sql[1], sql[2], sql[3], sql[4], sql[5], sql[6]);
or like in your case if you store sql values in array ctrl one by one this row can be written simply as:
[Updated on: Mon, 07 May 2007 15:45] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Sat Apr 26 19:25:08 CEST 2025
Total time taken to generate the page: 0.00553 seconds
|
|
|