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 » U++ SQL Begginer
U++ SQL Begginer [message #17302] Wed, 06 August 2008 14:15 Go to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

hello all

i want to make a program that have embedded database like SQLApp Example

I Tried to Understand the code but it's hard

so please give me some guide lines
Re: U++ SQL Begginer [message #17308 is a reply to message #17302] Wed, 06 August 2008 16:41 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
I'm in the middle of creating Sql Topic++ documentation. I exported the main document so far to PDF and posted it (see attached). It may provide some guidance for a start.
Re: U++ SQL Begginer [message #17309 is a reply to message #17308] Wed, 06 August 2008 17:59 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

thanks very much ......i think it will be very useful

but i want to ask a Question ....i want to use embedded database in my program what type of database must i use

thanks
Re: U++ SQL Begginer [message #17310 is a reply to message #17309] Wed, 06 August 2008 18:28 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
Your best bet is to use SqlLite, since it will not need an installed database engine like MySQL or PostgreSQL. The database will simply be a file that sits next to your program.
Re: U++ SQL Begginer [message #17317 is a reply to message #17302] Wed, 06 August 2008 22:33 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
I did some work on the documentation. There is now 3 topic++ categories. It's basically a collection of knowledge from the forum , examples, and my own work. If anyone would like to contribute/edit/change the info, it would be great, just post back. I'll keep the working copy for now and just evolve it as we go.
See attached...
Re: U++ SQL Begginer [message #17324 is a reply to message #17317] Thu, 07 August 2008 13:03 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

thanks captainc

but i have a question

what is this
	SQL; // <------------- THIS

	Sqlite3Session sqlite3;
	if(!sqlite3.Open(ConfigFile("simple.db"))) {
		Exclamation("Can't create or open database file\n");
		return;
	}

	SQL = sqlite3;//<------------ And THIS
Re: U++ SQL Begginer [message #17325 is a reply to message #17324] Thu, 07 August 2008 15:23 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
Ahh, I just learned this, but there is only 1 SQL object being used in the background to manage all the sessions.

From sqls.h:
struct AppSql : Sql {
	void   operator=(SqlSource& s) { Assign(s); }
	void   Detach()                { Sql::Detach(); }
	AppSql() : Sql(NULLSQL) {}
};
AppSql& AppCursor();
#define SQL AppCursor()


When you make an Sql object, that sql object you make will actually call the global SQL object
For example, from sql.cpp:
Sql::Sql(const char *stmt) {
	cn = SQL.GetSession().CreateConnection();
	SetStatement(stmt);
}


The sqlite3 example you are referencing shows an alternate way of working with the sql packages, calling on the SQL object itself. Instead, to keep it all similar, do something like this:
Sqlite3Session m_session;
bool good_conn = m_session.Open("my_database_file.db");
Sql sql(m_session); //define Sql object to act on Session object m_session.

Notice how I used Sqlite3Session just like I used PostgreSQLSession in the tutorial example. Also, I passed the session to the Sql object as well. Here we used the Sql object's constructor instead of assigning the sqlite3 object to the global SQL object.

Sqlite3Session m_session;
Sql sql(m_session);

- instead of -

Sqlite3Session sqlite3;
SQL = sqlite3;
Sql sql;

Other than that, it should otherwise be all the same.

Re: U++ SQL Begginer [message #17365 is a reply to message #17325] Sat, 09 August 2008 10:09 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

thanks captainc

but please can any one help me Understanding this code

void SQLApp::Query()
{
	SqlBool where;
	SqlSet borrowed = Select(BOOK_ID).From(BORROW_RECORD).Where(IsNull(RETURNED));
	if(query.status == 1)
		where = ID != borrowed;
	if(query.status == 2)
		where = ID == borrowed;
	SqlBool bdate;
	if(!IsNull(query.borrowed_from))
		bdate = BORROWED >= ~query.borrowed_from;
	if(!IsNull(query.borrowed_to))
		bdate = bdate && BORROWED <= ~query.borrowed_to;
	if(!bdate.IsEmpty())
		where = where && ID == Select(BOOK_ID).From(BORROW_RECORD).Where(bdate);
	book.Query(where);
}


it's from SQLApp Example
Re: U++ SQL Begginer [message #17366 is a reply to message #17365] Sat, 09 August 2008 14:12 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, you are build a condition to be use after 'where', based on status of several GUI widgets. Sometimes, elsewhere, this is called "dynamic SQL".

See the query dialog in the application and then look at the method again.

Mirek
Re: U++ SQL Begginer [message #17374 is a reply to message #17365] Sat, 09 August 2008 20:26 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
What you are looking at is where the Sql Upp classes become really powerful. As Mirek said, this is dynamic sql. The idea here is that you can assign parts of queries to variables and test them out individually, or put them together to form larger queries. You see the SqlBool object represents the section of a query where you would do a comparison. So you can say this:
Suppose NAME is a column in the tables NAME_TABLE1 and NAME_TABLE2:
// Build query:
SqlSet queryName1 = Select(NAME).From(NAME_TABLE1);
SqlBool nameIsSame = In(NAME,queryName1);
// Finish building and run query:
sql * Select(NAME).From(NAME_TABLE2).Where(nameIsSame);

SQL for this example would be:
SELECT name FROM name_table2 WHERE name IN (SELECT name FROM name_table1)

Granted you can do this more efficiently with joins and the such, but you should be able to get the idea.
Re: U++ SQL Begginer [message #17388 is a reply to message #17374] Tue, 12 August 2008 10:31 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

how can i give a column a default value in sqlite3

and if i want to save unix time format in database ..do i use INT or i use DOUBLE

thx in advance
Re: U++ SQL Begginer [message #17389 is a reply to message #17388] Tue, 12 August 2008 11:39 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

i want also to know how to remove a row from sqlarray

i want to remove it from the sqlarray not from the database
Re: U++ SQL Begginer [message #17390 is a reply to message #17388] Tue, 12 August 2008 13:19 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
TeCNoYoTTa wrote on Tue, 12 August 2008 04:31

how can i give a column a default value in sqlite3

Did you see the SQLDEFAULT keyword in the schema example from UppSqlBasicUse.pdf?

Quote:

and if i want to save unix time format in database ..do i use INT or i use DOUBLE

Did you see the TIME and DATE keywords in the schema example from UppSqlBasicUse.pdf?



Re: U++ SQL Begginer [message #17391 is a reply to message #17390] Tue, 12 August 2008 13:30 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

captainc wrote on Tue, 12 August 2008 14:19

TeCNoYoTTa wrote on Tue, 12 August 2008 04:31

how can i give a column a default value in sqlite3

Did you see the SQLDEFAULT keyword in the schema example from UppSqlBasicUse.pdf?

Quote:

and if i want to save unix time format in database ..do i use INT or i use DOUBLE

Did you see the TIME and DATE keywords in the schema example from UppSqlBasicUse.pdf?






i am very sorry .....i think i saw them but i forgot them as i stopped making database and did some Http messages

sorry again
Re: U++ SQL Begginer [message #17392 is a reply to message #17389] Tue, 12 August 2008 16:14 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
TeCNoYoTTa wrote on Tue, 12 August 2008 05:39

i want to remove it from the sqlarray not from the database


?

In that case, perhaps you do now want to use sqlarray in the first place.

Mirek
Re: U++ SQL Begginer [message #17393 is a reply to message #17392] Wed, 13 August 2008 11:18 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

does that mean i cant do that ??
Re: U++ SQL Begginer [message #17407 is a reply to message #17393] Wed, 13 August 2008 22:08 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
What it most likely means is that your design (or at least how you are approaching the problem) is off. Your query should be doing the filtering. Also, you can use the Sql class' Begin() method to ensure changes will not be finalized until a call to Commit().
Re: U++ SQL Begginer [message #17418 is a reply to message #17407] Thu, 14 August 2008 13:42 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

ok ....... i have another question

how can i get and handle sql row and if there is a datatype to save sql row in it
Re: U++ SQL Begginer [message #17423 is a reply to message #17418] Thu, 14 August 2008 16:46 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
Yes, I didn't get that far in the documentation yet... look at the examples for now, and I'll try to post an update soon to the basic use pdf.
Re: U++ SQL Begginer [message #17584 is a reply to message #17423] Thu, 21 August 2008 16:52 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
captainc wrote on Thu, 14 August 2008 10:46

Yes, I didn't get that far in the documentation yet... look at the examples for now, and I'll try to post an update soon to the basic use pdf.


What about uploading to svn as .tpp?

I believe that right now, we can handle a couple of unfinished docs Smile

Mirek
Previous Topic: SQL_ProgreSQL example building problems
Next Topic: SQL statment in constructor make program crash
Goto Forum:
  


Current Time: Fri Mar 29 10:51:33 CET 2024

Total time taken to generate the page: 0.01232 seconds