Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

support sending back rows changed #90

Merged
merged 1 commit into from Mar 13, 2015

Conversation

longinoa
Copy link
Contributor

This solves #82. We use the prefix of the first 3 characters to determine what type of request it is. Since we only have access to "columns" and "error" text use the column to display the type and the value to display the count.
scalar-return

@@ -86,7 +87,7 @@ private static String removeSuffix(String str, String[] suffixesToRemove) {
SQLiteDatabase database = openDatabase(databaseName);
try {
Cursor cursor = database.rawQuery("SELECT name FROM sqlite_master WHERE type=?",
new String[] { "table" });
new String[]{"table"});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't :)

@jasta
Copy link
Contributor

jasta commented Mar 11, 2015

Check the Travis build errors. I think they're lint related, which I don't have a great way to extract from Travis-CI at the moment. I just re-rungradle check and check out the XML file it generates.

@Tolriq
Copy link

Tolriq commented Mar 13, 2015

Seems my answer on original post was lost or I forget to push the button:(

Why don't you just check for no colums or count -1 in resulting cursor ? (if cursor null then it's an error)
Since the first query should be run asynchronous there's no problem starting another one after in this thread.

If no column then start new simple query 'select changes(), last_insert_rowid()' and return a MaxtrixCursor with 1 line / 1 row containing the data. (Can handle one last case when no change no row id for create database for example).

This sounds cleaner and can handle more things like create XXX, drop, ...
Even if less used those commands are used and should return something too.

@longinoa
Copy link
Contributor Author

@Tolriq yeah I thought about doing that.
You have to parse the type of query to find out if you should do select_changes or last_insert_rowId.
How do you dont know that it is a select w/ no rows returned?
What would you expect create/drop to return?

@Tolriq
Copy link

Tolriq commented Mar 13, 2015

A select without rows have the columns filled, so does not trigger this.

From the other problem about database mode change, I suppose that the database is opened / closed on each query / access.

So changes and last insert are the values corresponding to previous query so rule would be in order :

  • Cursor is null : Error
  • Cursor have colums : return cursor
  • Cursor have no colums : Do a "select changes(), last_insert_rowid()"
  • If last insert != 0 then return matrixCursor lastinsert and the id
  • If changes != 0 then return matrixCursor affectedRows and the count
  • If nothing then it's another command and since cursor is not null return a matrixCursor result and true.

This covers all cases and is simple to follow and maintain.

Of course this does not work if open / close assumption is wrong.

@longinoa
Copy link
Contributor Author

what would be returned for last_insert_id or select_changes for statements other than update/insert/delete? IE what is the return type for create table for instance?

Im just trying to figure out the value in the return from them to do an additional round trip.
From what I have seen it looks like the inspector ui does bizarre things when you dont return a "valid" result with the sql query disappearing. I think we can tackle that by returning a dummy result but if there is value in the return for the other calls I am more than happy to add it in.

@Tolriq
Copy link

Tolriq commented Mar 13, 2015

They return 0 if no query have made changes or insert, that why my previous post talked about != 0 to handle all known cases.

And yes that why I suggested using MatrixCursor that are valid cursors so will be correctly handled by Stetho and Inspector UI.

@longinoa
Copy link
Contributor Author

I think if they are congruent changes doing the smart thing and handling the return in the correct way rather than a second round trip to the database.

@@ -129,7 +187,13 @@ private SQLiteDatabase openDatabase(String databaseName) throws SQLiteException
}

public interface ExecuteResultHandler<T> {
public T handleResult(Cursor result) throws SQLiteException;
public T handleRawQuery(Cursor result) throws SQLiteException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be Cursor; it implies that the cursor came from database.rawQuery. Instead, prefer to parse changes(), last_insert_row_id() into two longs (or whatever type they are?)

@jasta
Copy link
Contributor

jasta commented Mar 13, 2015

Looks good except for nits. Please update the commit message of the rebased diff to include the summary in the pull request and "Closes #..." at the bottom. I recently learned that the pull request's metadata is not used for this feature, it must be in the commit itself. In general it's better to have the meta data in the commit anyway so that it is visible in the git history later.

@longinoa
Copy link
Contributor Author

I was planning on squashing and was going to update the commit message to have Closes # at the end

Previously we would only return a result for sql commands that were
selct statements. This diff makes `DatabasePeerManager` aware of what
commands are being executed and returns a result set appropriate to that
command.

Note: We are returning a result for all commands (including ones that do
not normally contain results like CREATE TABLE). We do this so that the
inspector interface will not remove the command.

Closes facebookarchive#82
longinoa added a commit that referenced this pull request Mar 13, 2015
support sending back rows changed
@longinoa longinoa merged commit 0d43c97 into facebookarchive:master Mar 13, 2015
@longinoa longinoa deleted the sql-return branch March 13, 2015 22:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants