What is the exact Java code snippet that you are using? On Thu, May 7, 2009 at 10:10 PM, Evan Ruff <evan.r...@gmail.com> wrote:
> > Vitali, > > I was just trying to match '?' in the SQL statement, such as: > > INSERT into users ( name, city ) VALUES( ?, ? ) > > so I can mash up my own prepare SQL statement. > > Also, I can run the test on the android phone to see if that might be > the problem. > > E > > On May 7, 4:36 pm, Vitali Lovich <vlov...@gmail.com> wrote: > > What's the code for the regexp that you are trying & what is the source > > string that you are matching against. > > > > On Thu, May 7, 2009 at 3:24 PM, Evan Ruff <evan.r...@gmail.com> wrote: > > > > > Vitali, > > > > > Thanks for your response! > > > > > That RegExp for the ? was giving me trouble, as it wouldn't match. > > > > > I also tried [\\?] without success as well. Any idea on how to find > > > that guy? > > > > > Thanks, > > > > > E > > > > > On May 7, 2:59 pm, Vitali Lovich <vlov...@gmail.com> wrote: > > > > Javascript & Java have different regular expressions, so if you are > > > running > > > > your stuff on desktop browsers in Hosted Mode but compiled mode in > > > Android, > > > > then you might be running into that problem. > > > > > > A performance improvement should be: > > > > > > String statement = new String( sqlStatement ); > > > > StringBuffer sb = new StringBuffer(statement.length()); > > > > int index; > > > > int previous = 0; > > > > int i = 0; > > > > > > while ((index = statement.indexOf('?')) != -1) > > > > { > > > > String firstPart = statement.substring( previous, index ); > > > > sb.append (firstPart).append('"').append(params[i++]).append('"'); > > > > previous = index + 1; > > > > > > } > > > > > > return sb.toString(); > > > > > > or try > > > > > > String statement = new String( sqlStatement ); > > > > String [] parts = statement.split("[?]"); > > > > StringBuffer sb = new StringBuffer(statement.length + parts.length * > > > > AVERAGE_PARAM_LENGTH); > > > > > > for (int i = 0; i < parts.length; i++) > > > > { > > > > sb.append(parts[i]).append('"').append(params[i]).append('"') > > > > > > } > > > > > > AVERAGE_PARAM_LENGTH can be anything, but you want the resultant > > > expression > > > > to be as close as possible to the actual final length as possible, > > > without > > > > going under (assuming this portion of code is your hotpath - > otherwise, > > > you > > > > won't notice the difference). > > > > > > On Thu, May 7, 2009 at 2:12 PM, Evan Ruff <evan.r...@gmail.com> > wrote: > > > > > > > Ok so something really fishy is going on with the Gears API. > > > > > > > I created my own "prepareSQLStatement" that converts the SQL Call > and > > > > > parameter list into a string. > > > > > > > private String prepareSQLStatement( String sqlStatement, > > > String[] > > > > > params ) throws DatabaseException > > > > > { > > > > > try > > > > > { > > > > > String statement = new String( sqlStatement > ); > > > > > > > for ( int i = 0; ( statement.indexOf( "?" ) > > 0 > > > ); > > > > > i++ ) > > > > > { > > > > > int index = statement.indexOf( '?' > ); > > > > > String firstPart = > statement.substring( > > > 0, > > > > > index ); > > > > > String secondPart = > statement.substring( > > > > > index + 1 ); > > > > > > > StringBuffer sb = new > StringBuffer(); > > > > > 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 it's string manipulation stack slightly > > > > > differently than all the other platforms? I've got a sneaky > suspecion > > > > > that the RegExp that's used to parse the '?' in the SQL commands > might > > > > > be failing? > > > > > > > Furthermore, can anyone give me an ideas as how to improve the > > > > > performance of the above method? It creates a noticable delay. Did > I > > > > > read somewhere that GWT has a slow string manipulation engine? > > > > > > > E > > > > > > > On May 6, 2:07 pm, Evan Ruff <evan.r...@gmail.com> wrote: > > > > > > Hey Eric, > > > > > > > > I'm pretty much terrified of Javascript. > > > > > > > > I'm a little hesitant to make any determination whatsoever as to > the > > > > > > cause of the problem. When I run the GWT Gears Sample > DatabaseDemo > > > > > > project, it works as expected. I can even replace all of the DB > > > > > > specifics with the internals of my tables/queries and it seems to > > > > > > work! It's just so freakin' frustrating. > > > > > > > > RememberTheMilk and the mobile GMail seem to make use of Gears on > > > > > > Android without issue, so I really don't know where to go from > here. > > > > > > Any other suggestions? > > > > > > > > Here's the replaced DatabaseDemo code, fwiw: > > > > > > > > public class Gears implements EntryPoint > > > > > > { > > > > > > private static final int NUM_SAVED_ROWS = 3; > > > > > > private static final int NUM_DATA_TABLE_COLUMNS = 3; > > > > > > > > private final Button addButton = new Button( "Add" ); > > > > > > private final Button clearButton = new Button( "Clear > > > Database" > > > > > ); > > > > > > private Database db; > > > > > > private final TextBox input = new TextBox(); > > > > > > private final FlexTable dataTable = new FlexTable(); > > > > > > > > public void onModuleLoad() > > > > > > { > > > > > > VerticalPanel outerPanel = new VerticalPanel(); > > > > > > outerPanel.setSpacing( 10 ); > > > > > > outerPanel.getElement().getStyle().setPropertyPx( > > > > > "margin", 15 ); > > > > > > > > HorizontalPanel textAndButtonsPanel = new > > > > > HorizontalPanel(); > > > > > > textAndButtonsPanel.add( new Label( "Enter a > Phrase: > > > " ) > > > > > ); > > > > > > textAndButtonsPanel.add( input ); > > > > > > textAndButtonsPanel.add( addButton ); > > > > > > textAndButtonsPanel.add( clearButton ); > > > > > > outerPanel.add( textAndButtonsPanel ); > > > > > > outerPanel.add( new Label( "Last 3 Entries:" ) ); > > > > > > outerPanel.add( dataTable ); > > > > > > > > for ( int i = 0; i <= NUM_SAVED_ROWS; ++i ) > > > > > > { > > > > > > dataTable.insertRow( i ); > > > > > > for ( int j = 0; j < > NUM_DATA_TABLE_COLUMNS; > > > j++ > > > > > ) > > > > > > { > > > > > > dataTable.addCell( i ); > > > > > > } > > > > > > } > > > > > > dataTable.setWidget( 0, 0, new HTML( "<b>Id</b>" > ) ); > > > > > > dataTable.setWidget( 0, 1, new HTML( > "<b>Phrase</b>" > > > ) ); > > > > > > dataTable.setWidget( 0, 2, new HTML( > > > "<b>Timestamp</b>" ) > > > > > ); > > > > > > > > // Create the database if it doesn't exist. > > > > > > try > > > > > > { > > > > > > db = > Factory.getInstance().createDatabase(); > > > > > > db.open( "database-demo" ); > > > > > > > > db.execute( "DROP TABLE IF EXISTS user" > ); > > > > > > db.execute( "CREATE TABLE IF NOT EXISTS > user > > > ( > > > > > user_id TEXT NOT > > > > > > NULL, sessionId TEXT, name TEXT, email TEXT )" ); > > > > > > } > > > > > > catch ( DatabaseException e ) > > > > > > { > > > > > > RootPanel.get( "demo" ).add( new HTML( > "Error > > > > > opening or creating > > > > > > database: <font color=\"red\">" + e.toString() + "</font>" ) ); > > > > > > // Fatal error. Do not build the > interface. > > > > > > return; > > > > > > } > > > > > > > > input.addKeyboardListener( new > > > KeyboardListenerAdapter() > > > > > > { > > > > > > @Override > > > > > > public void onKeyDown( Widget sender, > char > > > > > keyCode, int modifiers ) > > > > > > { > > > > > > if (keyCode == > > > > > KeyboardListener.KEY_ENTER) > > > > > > { > > > > > > insertPhrase(); > > > > > > } > > > > > > } > > > > > > } ); > > > > > > > > addButton.addClickListener( new ClickListener() > > > > > > { > > > > > > public void onClick( Widget sender ) > > > > > > { > > > > > > insertPhrase(); > > > > > > } > > > > > > } ); > > > > > > > > clearButton.addClickListener( new ClickListener() > > > > > > { > > > > > > public void onClick( Widget sender ) > > > > > > { > > > > > > clearPhrases(); > > > > > > displayRecentPhrases(); > > > > > > } > > > > > > } ); > > > > > > > > RootPanel.get( "demo" ).add( outerPanel ); > > > > > > displayRecentPhrases(); > > > > > > } > > > > > > > > /** > > > > > > * Remove all phrases from the database. > > > > > > */ > > > > > > private void clearPhrases() > > > > > > { > > > > > > try > > > > > > { > > > > > > db.execute( "DELETE FROM Phrases" ); > > > > > > } > > > > > > catch ( DatabaseException e ) > > > > > > { > > > > > > Window.alert( e.toString() ); > > > > > > } > > > > > > } > > > > > > > > /** > > > > > > * Fill the labels with the phrases from the database. > > > > > > */ > > > > ... > > > > read more ยป > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---