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 » Some questions around SQlite3
Some questions around SQlite3 [message #28430] Wed, 01 September 2010 20:08 Go to next message
mubeta is currently offline  mubeta
Messages: 77
Registered: October 2006
Member
Hi guys,
Some question around SQlite3:

1) I am using a thirdy part database, and I want to inser new values in the table. Now I am using this way:
...
	Sqlite3Session db1;
	if(!db1.Open(fName)) 
	{
                //statements
		return;
	}

        SQL = db1;

        Sql sql;

        //Statements

        sql*Insert("Project")("Id", i)("DbNum", daveDbNum)("Start", daveStart)("Length", daveLen)("Buff", daveMem1.strValues);

        //Statements

        db1.Close();


Questions:
1.1) How thw object named "sql" is linked to the object named "db1" ?? I reach this source code following some u++ reference code, but I don't understand how db1 and sql are connectd. The application is working correctly.

1.2) I saw that using SQL.Execute(), can send the queries as I most like; but, in the same source code, how I can send an String of binary values ? Example:
  Sqlite3Session db1;
  db1.Open(fName);
  SQL = db1;

  SQL.Execute("INSERT INTO table (field1, field2) VALUES ('1', + String(foo) + "')");

where "foo" are binary values. Sometime this way result in an error, because in the string it's included the char('). Ther eis some encoder/decoder for solve this problem?

2) When using SELECT statement in the query, next using Fetch(), I can get the fileds values, but only indexable with number:
  Sqlite3Session db1;
  db1.Open(fName);
  SQL = db1;
  Sql sql;

  sql.Execute("SELECT * FROM table");

  while(sql.Fetch()) PromptOK(sql[5]); // Working correctly
  while(sql.Fetch()) PromptOK(sql(SqlId("Name"))); // Does not work ??


Question: How I can get the index of the fields, from the field name? When I am using a thirdy part database, I don't know the index of the fields!

Thanks a lot.
Re: Some questions around SQlite3 [message #28432 is a reply to message #28430] Wed, 01 September 2010 21:13 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 693
Registered: December 2005
Location: Budapest, Hungary
Contributor
1. SQL is a macro, same as calling AppCursor() function. The relevant code:
#ifndef NOAPPSQL

struct AppSql : Sql {
	void   operator=(SqlSource& s) { Assign(s); }
	void   Detach()                { Sql::Detach(); }
	AppSql() : Sql(NULLSQL) {}
};

AppSql& AppCursor();
#define SQL AppCursor()
#endif

1.2 Use SqlBinary(foo)

2. You can use the field name in the first while loop. Fetching after the last record fetched returns false. Your second while loop will not run.

[Updated on: Wed, 01 September 2010 21:14]

Report message to a moderator

Re: Some questions around SQlite3 [message #28434 is a reply to message #28432] Wed, 01 September 2010 21:32 Go to previous messageGo to next message
mubeta is currently offline  mubeta
Messages: 77
Registered: October 2006
Member
Quote:


2. You can use the field name in the first while loop. Fetching after the last record fetched returns false. Your second while loop will not run.



I know this. In my example I just want to show that I wish to use the field name, and not the filed index. But I don't found any way for do it.
I need only one while, but i want to get values using something like: Value var = sql["FieldName"]; and not on number; or, how to get the corresponding index, from the FieldName.

Ok for the answer 1), but this mean that, time by time I can only open one database?

Thanks.
Re: Some questions around SQlite3 [message #28437 is a reply to message #28434] Wed, 01 September 2010 23:48 Go to previous message
zsolt is currently offline  zsolt
Messages: 693
Registered: December 2005
Location: Budapest, Hungary
Contributor
Ok, now I understand it. The correct syntax is: Value var = sql[SqlId("FieldName")];

Quote:

time by time I can only open one database?


No, this appsql thing is only for convenient db handling in most applications, where only one database is needed. You can open as many sessions as you want in your app and can use that sessions in any Sql object's constructor.
Previous Topic: Prefix to prevent name clash in SQL: SqlId, variables, tables, ...
Next Topic: SQlite3: my problem or bug?
Goto Forum:
  


Current Time: Thu Mar 28 21:27:28 CET 2024

Total time taken to generate the page: 0.00941 seconds