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 » Community » Newbie corner » SqlVal to int (Typecast) (Typecasting from sqlval type to other types)
SqlVal to int (Typecast) [message #45174] Wed, 23 September 2015 06:25 Go to next message
ayana is currently offline  ayana
Messages: 16
Registered: November 2011
Promising Member
Hey All,

SqlVal ro;
Sql UserQuerySql;
UserQuerySql.Clear();
UserQuerySql * Select (Count(MBVARINDEX)).From ( PARAMETER );
while ( UserQuerySql.Fetch() )
{
ro=Count(MBVARINDEX);
}

In the above query whatever the count value I am getting is of type 'SqlVal',I want that to typecast into 'Int', Let me know how to do typecasting for it.

Thanks & Regards,

[Updated on: Wed, 23 September 2015 06:30]

Report message to a moderator

Re: SqlVal to int (Typecast) [message #45175 is a reply to message #45174] Wed, 23 September 2015 06:58 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1779
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi ayana,

ayana wrote on Wed, 23 September 2015 06:25
SqlVal ro;
Sql UserQuerySql;
UserQuerySql.Clear();
UserQuerySql * Select (Count(MBVARINDEX)).From ( PARAMETER );
while ( UserQuerySql.Fetch() )
{
ro=Count(MBVARINDEX);
}

In the above query whatever the count value I am getting is of type 'SqlVal',I want that to typecast into 'Int', Let me know how to do typecasting for it.

This SqlVal is actually only representation of sql column used when constructing the query. What you need is the result, which is accesible via the Sql object after calling Fetch:
int ro;
Sql UserQuerySql;
UserQuerySql.Clear();
UserQuerySql * Select (Count(MBVARINDEX)).From ( PARAMETER );
while ( UserQuerySql.Fetch() )
{
  ro=sql[0];
}

See the Sql tutorial, it demonstrates this and many other useful and important thing about sql in U++.

Best regards,
Honza
icon7.gif  Re: SqlVal to int (Typecast) [message #45176 is a reply to message #45175] Wed, 23 September 2015 07:14 Go to previous messageGo to next message
ayana is currently offline  ayana
Messages: 16
Registered: November 2011
Promising Member
Hey Honza,

Yep,it works.
Thank you.
Re: SqlVal to int (Typecast) [message #45224 is a reply to message #45176] Sat, 10 October 2015 01:01 Go to previous messageGo to next message
Alboni is currently offline  Alboni
Messages: 203
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
Hi, I'm using the same code for MySql and SqLite versions of my program and I'd like to point out that using
ro=sql[0];
can behave rather quirky.. in combination with functions like Sum() or Count()
Depending of which db you use, Count, Sum etc. could be presented as int or a String type. Confusing.

A better way (especially if you would select more than one column) is to use the As function:
UserQuerySql * SqlSelect (SqlCount(MBVARINDEX).As(MBVARINDEX)).From ( PARAMETER );
while ( UserQuerySql.Fetch() )
{
  ro=sql[MBVARINDEX];
}

I also like to use SqlSelect, SqlSum, SqlCount etc. because the other terms are so generic there are often clashes.

[Updated on: Sat, 10 October 2015 01:04]

Report message to a moderator

Re: SqlVal to int (Typecast) [message #45225 is a reply to message #45224] Sat, 10 October 2015 06:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13045
Registered: November 2005
Ultimate Member
Alboni wrote on Sat, 10 October 2015 01:01
Hi, I'm using the same code for MySql and SqLite versions of my program and I'd like to point out that using
ro=sql[0];
can behave rather quirky.. in combination with functions like Sum() or Count()
Depending of which db you use, Count, Sum etc. could be presented as int or a String type. Confusing.

A better way (especially if you would select more than one column) is to use the As function:
UserQuerySql * SqlSelect (SqlCount(MBVARINDEX).As(MBVARINDEX)).From ( PARAMETER );
while ( UserQuerySql.Fetch() )
{
  ro=sql[MBVARINDEX];
}

I also like to use SqlSelect, SqlSum, SqlCount etc. because the other terms are so generic there are often clashes.


Interesting. Can you be more specific about the issue, like providing example which fails? (and on what DB?)

Mirek
Re: SqlVal to int (Typecast) [message #45401 is a reply to message #45174] Mon, 09 November 2015 02:20 Go to previous message
Alboni is currently offline  Alboni
Messages: 203
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
Well, this seems to be old news. In 2012 I ran in the problem that SqlSum(some int) would be a String value when Fetching with MySql(5.5) and an int value when using SqLite. That problem would be ommited by Using As( )
If I try it now, both are int values.
I'll let you know if I find a way to reproduce it with the new upp after all.
Previous Topic: Help: GetSysTime()
Next Topic: Usage of Iml image data leads to linker error
Goto Forum:
  


Current Time: Fri Jan 22 05:11:33 CET 2021

Total time taken to generate the page: 0.02072 seconds