Archived Thread: 'MySql and GetCount'
-
MySql and GetCountPosted by adolfojp on Thursday, July 26, 2007I executed a GetCount() method with a Sql Server Express database and it worked flawlessly. However, when I switch the database to MySQL I get the following error message. [example] An exception of type 'System.InvalidCastException' occurred in SubSonic.DLL but was not handled in user code Additional information: Specified cast is not valid. [/example] The code is really simple. It goes like this: [code language=C#] SubSonic.Query query = new SubSonic.Query(MySqlSonic.Data.User.Schema.TableName); Response.Write(query.GetCount("UserName")); [/code] Am I doing something wrong? Is this a bug? :-( Thanks in advanced guys.
-
Reply: MySql and GetCountPosted by bderosa on Tuesday, October 30, 2007Im having the same problem using MySQL & GetCount - have you found a workaround?
-
Reply: MySql and GetCountPosted by sde on Wednesday, October 31, 2007It is old, many times reported bug, which no one cares :) Without any known (for me) workaround.
-
Reply: MySql and GetCountPosted by Harv on Wednesday, October 31, 2007That's still buggy? I had implemented a workaround/fix back in the 1.x days for that method not working properly. I think this came up because I wanted to do paging of a GridView.
-
Reply: MySql and GetCountPosted by zowens on Wednesday, October 31, 2007Use GetRecordCount()
-
Reply: MySql and GetCountPosted by sde on Thursday, November 01, 2007It doesnt work either.
-
Reply: MySql and GetCountPosted by zowens on Thursday, November 01, 2007By "It Doesn't Work" what do you mean? It doesn't return the corect result? You might try inspecting your query or maybe consider a SP.
-
Reply: MySql and GetCountPosted by sde on Thursday, November 01, 2007I mean "{DBNAME}.GETCOUNT() doesnt exist" or something like that. It deosnt return anything, just throws unhandled exception. It exists even for simplest query. And why i should consider a SP for a bug in provider?
-
Reply: MySql and GetCountPosted by bderosa on Thursday, November 01, 2007What about just fixing the issue at hand? GetCount throws a type-cast exception. I'm not exactly sure what's going on, but I did notice that MySQL returns a LONG when getting the count yet the GetCount() method returns an INT. If this *is* the actual issue at hand, would this not be a simple issue to patch? Also, I attempted to use the GetRecordCount() static method on the DataService class but it failed as well throwing a MySqlException: "FUNCTION myTableName.COUNT does not exist" Let me know if there are other workarounds to try - currently, I'm reconstructing the query manually using SQL and then getting a count from that. While it works, it'd be nice to commit to using SQL or the Query/QueryCommand objects.
-
Reply: MySql and GetCountPosted by sde on Friday, November 02, 2007I think problem lies elsewhere. Query qr = TableName.CreateQuery(); int foo = qr.GetRecordCount(); Generates SELECT COUNT (1) FROM `TableName`, But should SELECT COUNT(1) FROM `TableName` (without space between Count word and first bracket)
-
Reply: MySql and GetCountPosted by zowens on Saturday, November 03, 2007Then it's a provider error... or a subsonic issue.
-
Reply: MySql and GetCountPosted by sde on Saturday, November 03, 2007Tadam! So i dont have to write SP`s now?:) And being serious - is there a person who can commit a fix into SVN? This thread will be forgotten in one week, and in next version we will have this bug again.
-
Reply: MySql and GetCountPosted by LarryB on Tuesday, November 06, 2007I spent one evening searching through this trying to figure out what is causing this issue. I couldn't track it down. I wanted to get with eric to see if he could walk through the code with me to try and track it down, but in the times I have been available I haven't been able to grab him. I will say it again, I am and have been very busy lately. I wish I had more time to dedicate to fixing these things, but it has been very short. If you can find/provide a solution I would be more than happy to hear it, look at it, test it and put it in the code.
-
Reply: MySql and GetCountPosted by spookytooth on Wednesday, December 12, 2007Please people - the power of OpenSource is embracing and helping with patches. I know we have to be responsible for what we make and I'm down with that - but the idea here is that it's Open and FREE and people get together like hippies in an Oregon forest and pack their pipes full of code... Patch me!
-
Re: Reply: MySql and GetCountPosted by canofunk on Thursday, December 27, 2007
Fixed in Revision 234
-
Re: Reply: MySql and GetCountPosted by vmirage on Tuesday, August 05, 2008
I think i'm getting the same issue with SubSonic 2.1 Final. It was fine previously with SubSonic 2.1 beta 3.
Is the bug back?
-
Re: Reply: MySql and GetCountPosted by Mairon on Tuesday, August 19, 2008
I fixed source in DataProvider.cs, removing space between COUNT and (1):
public virtual int GetRecordCount(Query qry)
{
string select = SqlFragment.SELECT + "COUNT(1) FROM ";
if(qry.IsDistinct && !String.IsNullOrEmpty(qry.SelectList))
{
string[] distinct = qry.SelectList.Split(new char[] {','});
select = SqlFragment.SELECT + "COUNT(DISTINCT " + distinct[0] + ") FROM ";
}
QueryCommand qc = BuildSelectCommand(select + Utility.QualifyColumnName(qry.Schema.SchemaName, qry.Schema.Name, qry.Provider) + BuildWhere(qry), qry);
qc.CommandType = CommandType.Text;
object obj = ExecuteScalar(qc);
if(obj != null)
{
return (int)obj;
}
else
{
return 0;
}
}