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 » fetch not reading into struct
fetch not reading into struct [message #32661] Wed, 01 June 2011 02:11 Go to next message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 219
Registered: June 2011
Experienced Member
I have a session created with MSSQL and am reading from a view in SQL server. My .sch file looks like this:

TABLE_ (PUNCH_VIEW)
	STRING_ (EMPLOYEE_ID, 6)
	STRING_ (FIRST_NAME, 15)
	STRING_ (LAST_NAME, 16)
END_TABLE


Now, when I create a session, I'm running over VPN so I have to impersonate first, then I create my connection and try to run a select:
S_PUNCH_VIEW view;

Sql sql(dbSession);
sql * Select(view).From(PUNCH_VIEW);

while(sql.Fetch(view))
{
    if(view.FIRST_NAME == "John")
    {
        // add this text to a GridCtrl
    }

    // Add data to GridCtrl
    grid.Add(sql);
}


For some reason the fetch is not filling S_PUNCH_VIEW "view" with any data. It's just empty through each cycle in the loop, but grid.Add(sql) actually works and displays the data.

Additionally if I try sql[FIRST_NAME] instead, I get an exception: "Assertion failed in Sql.cpp line 287 0". Any hints as to what I'm doing wrong?
Re: fetch not reading into struct [message #32664 is a reply to message #32661] Wed, 01 June 2011 08:34 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

jjacksonRIAB wrote on Wed, 01 June 2011 03:11

I have a session created with MSSQL and am reading from a view in SQL server. My .sch file looks like this:

TABLE_ (PUNCH_VIEW)
	STRING_ (EMPLOYEE_ID, 6)
	STRING_ (FIRST_NAME, 15)
	STRING_ (LAST_NAME, 16)
END_TABLE


Now, when I create a session, I'm running over VPN so I have to impersonate first, then I create my connection and try to run a select:
S_PUNCH_VIEW view;

Sql sql(dbSession);
sql * Select(view).From(PUNCH_VIEW);

while(sql.Fetch(view))
{
    if(view.FIRST_NAME == "John")
    {
        // add this text to a GridCtrl
    }

    // Add data to GridCtrl
    grid.Add(sql);
}


For some reason the fetch is not filling S_PUNCH_VIEW "view" with any data. It's just empty through each cycle in the loop, but grid.Add(sql) actually works and displays the data.

Additionally if I try sql[FIRST_NAME] instead, I get an exception: "Assertion failed in Sql.cpp line 287 0". Any hints as to what I'm doing wrong?



Maybe you should try:
[code]
Sql sql(dbSession);
sql * Select(EMPLOYEE_ID, FIRST_NAME, LAST_NAME).From(PUNCH_VIEW);

while(sql.Fetch(view))
{
    if(view[FIRST_NAME] == "John")
    {
        // add this text to a GridCtrl
    }

    // Add data to GridCtrl
    grid.Add(sql);
}
[/code]

Re: fetch not reading into struct [message #32666 is a reply to message #32664] Wed, 01 June 2011 08:51 Go to previous messageGo to next message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 219
Registered: June 2011
Experienced Member
When I do that I get a compiler error (MSVC 2010):

error C2676: binary '[' : 'S_PUNCH_VIEW' does not define this operator or a conversion to a type acceptable to the predefined operator

If I switch it to sql[FIRST_NAME], I get "Assertion failed in e:\upp\uppsrc\Sql\Sql.cpp, line 287 0" at:

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();
}

Re: fetch not reading into struct [message #32670 is a reply to message #32666] Wed, 01 June 2011 10:31 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

try use upper case SQL, and use SQL instead view:
SQL = dbSession
SQL * Select(EMPLOYEE_ID, FIRST_NAME, LAST_NAME).From(PUNCH_VIEW);

while(SQL.Fetch(view))
{
    if(SQL[FIRST_NAME] == "John")
    {
        // add this text to a GridCtrl
    }

}


A better example look in HomeBuget package.

[Updated on: Wed, 01 June 2011 10:41]

Report message to a moderator

Re: fetch not reading into struct [message #32673 is a reply to message #32670] Wed, 01 June 2011 11:54 Go to previous message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 219
Registered: June 2011
Experienced Member
I see what I did. When I was writing my .sch file I was going off of column alias names instead of the actual column names behind them. My mistake.

Thanks for your help!

Previous Topic: Creating a TIMESTAMP column in MySQL
Next Topic: Sqlite with U++
Goto Forum:
  


Current Time: Fri Mar 29 16:14:11 CET 2024

Total time taken to generate the page: 0.01311 seconds