Guys,
I think there is something seriously fishy going on with the GWT Gears
API. While I am able to run the Gears Sample Database project that
comes with the GWT API on the phone, I am not able to get ANY of my
parameterized queries to run on the phone. So, I wrote my own
prepareSQLStatement:
Ok so something really fishy is going on with the Gears API.
private String prepareSQLStatement( String statement, String[]
params ) throws DatabaseException
{
try
{
for ( int i = 0; ( statement.indexOf( "?" ) > 0 ); i++ )
{
int index = statement.indexOf( '?' );
String firstPart = statement.substring( 0,
index );
String secondPart = statement.substring( index
+ 1 );
StringBuilder sb = new StringBuilder();
sb.append( firstPart ).append( "\"" ).append(
params[ i ] ).append
( "\"" ).append( secondPart );
statement = sb.toString();
}
return statement;
}
catch ( IndexOutOfBoundsException indexOut )
{
throw new DatabaseException( "Index out of bounds. SQL
Parameter
Error" );
}
}
When I use this method to prepare the statement before hitting
db.execute, all of my sql statements work as expected.
Could Android implement the string manipulation/regexp stack slightly
differently than all the other platforms? I've got a sneaky suspicion
that the RegExp that's used to parse the '?' in the SQL commands might
be failing?
E
On May 5, 7:05 pm, Evan Ruff <[email protected]> wrote:
> Hey guys,
>
> I've got a pretty heavy gears app the works great in IE, Firefox and
> Chrome; however, I'm getting some inconsistencies when running it on
> Android using Gears GWT API 1.2.0. Whenever I seem to run ANY query, I
> get a "Wrong number of SQL parameters" DatabaseException. Everything
> works perfectly in the other browsers.
>
> I'm debugging back to the client and my info is:
> Exception Message: Wrong number of SQL parameters.
> Method: selectUserByUserId
> Parameters: [ 1 ]
>
> Here is the method:
>
> private static final String SELECT_USER = "SELECT user_id, sessionId,
> name, email FROM user WHERE user_id = ?";
>
> public User selectUserByUserId( long userId )
> {
> final String[] params = new String[] { Long.toString
> ( userId ) };
> try
> {
> ResultSet rs = db.execute( SELECT_USER, params );
> for ( int i = 0; rs.isValidRow(); ++i, rs.next() )
> {
> User user = new User();
> user.setId( rs.getFieldAsLong( 0 ) );
> user.setCurrentSessionId( rs.getFieldAsString
> ( 1 ) );
> user.setName( rs.getFieldAsString( 2 ) );
> return user;
> }
> rs.close();
> }
> catch ( DatabaseException e )
> {
> debugDBException( "selectUserByUserId", params, e );
> }
> return null;
>
> }
>
> The debugDBException method just rolls everything up an submits it to
> the server.
>
> Has anone else had this sort of issue working with Gears on Android?
> I've tried the test 1.2 Gears LocalDB Test and it seems to fine. It
> looks like I'm trying to do a VERY similar thing and I'm really
> perplexed as to why it won't work.
>
> Oh also, I should add, that I checked out the DB structure using the
> little DB explorer guy that is available in the vanilla gears distro.
>
> The SQLite DB looks identical as the one on the other platforms, just
> without data ('cause of all the SQL errors, I assume)
>
> Thanks!
>
> Evan
>
> PS. Sorry about the cross post. I'm just never sure where to put these
> Gears/GWT questions!