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 » Lowercase field name in table - error
Lowercase field name in table - error [message #36739] Sat, 30 June 2012 00:51 Go to next message
mezise is currently offline  mezise
Messages: 54
Registered: April 2006
Member
I try to use Upp with existing database where there are lowercase field names and I get "Assertion failed" error in NEVER() line:

C:\uppSVN5061\uppsrc\Sql\Sql.cpp, line 339

Value Sql::operator[](SqlId id) const {
	String s = ~id;
	for(int i = 0; i < cn->info.GetCount(); i++)
		if(cn->info[i].name == s)
			return operator[](i);
	NEVER(); // <---- here ----
	return Value();
}


To repeat error:
- revision: SVN 5061
- use package: reference/SQL_Sqlite3
- in simple.sch: change ID to id
- in simple.cpp: change all ID to id
- Execute
Re: Lowercase field name in table - error [message #36781 is a reply to message #36739] Wed, 04 July 2012 15:25 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Should be now fixed. Anyway, the cause is that you are using lower-cased SqlIds, which is somewhat, well, unexpected; DB column names are uppercased.
Re: Lowercase field name in table - error [message #36785 is a reply to message #36781] Thu, 05 July 2012 09:49 Go to previous messageGo to next message
mezise is currently offline  mezise
Messages: 54
Registered: April 2006
Member
Thank you for the answer.
Unfortunately the error still appears in SVN5110, and revealed a new one during compilation:
C:\uppSVN5110\reference\SQL_Sqlite3\simple.cpp(17) : error C2039: 'LogErrors' : is not a member of 'Upp::Sqli
	te3Session'
        C:\uppSVN5110\uppsrc\plugin/sqlite3/Sqlite3.h(19) : see declaration of 'Upp::Sqlite3Session'

After commenting
sqlite3.LogErrors(true);

lowercase field name error still appears.


PS. In sqlite and mysql worlds there are a lot of tables with lowercase field names Smile
Re: Lowercase field name in table - error [message #36786 is a reply to message #36785] Thu, 05 July 2012 10:01 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
...but it was fixed in 5113 Smile (With LogErrors as well).

See http://www.ultimatepp.org/redmine/projects/upp/repository

Mirek
Re: Lowercase field name in table - error [message #36788 is a reply to message #36786] Thu, 05 July 2012 11:01 Go to previous messageGo to next message
mezise is currently offline  mezise
Messages: 54
Registered: April 2006
Member
Ups, sorry, I thought that last builds are on http://www.ultimatepp.org/www$uppweb$nightly$en-us.html
Re: Lowercase field name in table - error [message #36789 is a reply to message #36788] Thu, 05 July 2012 11:11 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Last builds yes, but they get build in night, not the moment I commit the change. Plus, sometimes nightly building fails...
Re: Lowercase field name in table - error [message #36790 is a reply to message #36789] Thu, 05 July 2012 11:57 Go to previous messageGo to next message
mezise is currently offline  mezise
Messages: 54
Registered: April 2006
Member
I checked out from repository. Works like a charm. Thank you.
Re: Lowercase field name in table - error [message #36795 is a reply to message #36781] Thu, 05 July 2012 18:32 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
Hello, Mirek.
mirek wrote on Wed, 04 July 2012 15:25

Should be now fixed. Anyway, the cause is that you are using lower-cased SqlIds, which is somewhat, well, unexpected; DB column names are uppercased.

From the source code point of view, there is no problem to create case-sensitive column names, at least for SQLite. The code, which uppercase column names, is on U++ side:
for(int i = 0; i < cn->info.GetCount(); i++)
	cn->info[i].name = ToUpper(cn->info[i].name);

Commenting such part of code removes "case-insensitive restriction" of reading column names (but not the other restrictions with the same case-insensitive characters, inside other U++ source code, e.g. id, ID).
In opposite of uppercase, I read about lowercase identifiers on MySQL documentation.
So, in conclusion, I think, it is related to various database support on U++ side, but not a real restrictions of concrete database (e.g. SQLite) or even C++ identifiers, which are case-sensitive. Therefore, "the fix" fixes the effects, but not the cause, which created by some purpose.

[Updated on: Thu, 05 July 2012 19:09]

Report message to a moderator

Re: Lowercase field name in table - error [message #36796 is a reply to message #36795] Thu, 05 July 2012 19:52 Go to previous messageGo to next message
mezise is currently offline  mezise
Messages: 54
Registered: April 2006
Member
Even with the fix, code such:
ValueMap row;
sql.Execute("SELECT COUNT(*) cnt FROM info");
sql.Fetch(row);
DUMP(row);

gives in log file:
row = { CNT: 12}

instead of:
row = { cnt: 12}


Commenting the code mentioned by Sender Ghost in <the cause> link fixes this issue, but I guess there is a reason for this code.
Re: Lowercase field name in table - error [message #36798 is a reply to message #36795] Fri, 06 July 2012 09:05 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Sender Ghost wrote on Thu, 05 July 2012 12:32


In opposite of uppercase, I read about lowercase identifiers on MySQL documentation.



Actually, if anything, I believe that above link is more or less supportive to make everything uppercase.

If you consider

sql.Execute("SELECT COUNT(*) cnt FROM info");


then it is not unlikely that some DB returns "CNT".

As case sensitivity itself is DB dependent issue, having everything insensitive and upper-case on U++ side seems like the most prudent option.

Mirek
Re: Lowercase field name in table - error [message #36799 is a reply to message #36798] Fri, 06 July 2012 10:25 Go to previous message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
In case of SQLite, it returns original column name(s), independent from the query case-sensitivity:
sqlite> .header on
sqlite> .mode column
sqlite> create table SIMPLE_TEST1 (id integer primary key, NAME text, LASTNAME text, BDATE integer);
sqlite> insert into SIMPLE_TEST1(id, NAME, LASTNAME, BDATE) values (0, 'Joe', 'Smith', 20000101);
sqlite> insert into SIMPLE_TEST1(id, NAME, LASTNAME, BDATE) values (1, 'Mike', 'Smith', 20000102);
sqlite> insert into SIMPLE_TEST1(id, NAME, LASTNAME, BDATE) values (2, 'Jon', 'Goober', 20000103);
sqlite> select id, NAME, LASTNAME, BDATE from SIMPLE_TEST1;
id          NAME        LASTNAME    BDATE
----------  ----------  ----------  ----------
0           Joe         Smith       20000101
1           Mike        Smith       20000102
2           Jon         Goober      20000103
sqlite> select ID, NAME, LASTNAME, BDATE from SIMPLE_TEST1;
id          NAME        LASTNAME    BDATE
----------  ----------  ----------  ----------
0           Joe         Smith       20000101
1           Mike        Smith       20000102
2           Jon         Goober      20000103

But yes, I'm aware about possible ambiguities/differences between database engines and why uppercase used instead of lowercase (e.g. because of global SqlId(s) and possible lowercase local variables inside developer's source code). While this didn't change the conclusion, in my opinion.

Personally, I thought about access to column names with the case-sensitivity of constructed query. I already did something inside another topic.

Nevertheless, I agree, that in the current constraints, what you did is "the most prudent option".

[Updated on: Fri, 06 July 2012 10:48]

Report message to a moderator

Previous Topic: What does this code do exactly?
Next Topic: Cannot connect to MySQL database
Goto Forum:
  


Current Time: Thu Mar 28 14:15:39 CET 2024

Total time taken to generate the page: 0.01941 seconds