0

OK, so I am trying to update what is in my table and I want the results without having to do two separate queries. I'm using SQLiteStudio. If I try to do two queries at the same time when I press F9 (Update + Set + Where; and Select + From;), it'll say the query finished, but no rows are loaded and nothing is updated. If I try to do the Update + Set + Where first, it'll update the row but no results. Then I have the do the Select + From query and when I press F9, this time, it shows the updated result. I don't understand why I have to do it in two queries.

The table looks like this:

|ID|FirstName|MiddleName|LastName|
|1 |         |          |        |

The code looks like this:

UPDATE Test1
SET FirstName = 'Jacob'
WHERE ID = 1;

SELECT * FROM Test1;

So my question is how do I go about updating the results and displaying the results in one query? Note: I only have one table.

rumpled105
  • 27
  • 5
  • SQLiteStudio - by default - executes only current query (currently under the cursor). Please try selecting both queries (with mouse, or with Ctrl+a) and then hit Execute. You can change this default behavior in options. – Googie May 05 '17 at 22:40
  • Ah, OK. Now it's working when I select all and then execute. Still a little disappointed it has to be in two queries. But that's good enough for me. By the way, @Googie, it probably would have been best for you to reply as an answer and not as a comment so I can accept yours as the answer. – rumpled105 May 06 '17 at 00:58

2 Answers2

0

A few suggestions:

  1. Can you remove the mid-statement semi-colon? So:

    UPDATE Test1 SET FirstName = 'Jacob' WHERE ID = 1

    SELECT * FROM Test1;

  2. Not sure what ORM/SqlData Connection you are using, but if removing the semicolon above does not work, split the statements into 2 separate query statements (which you already said/know it works). That is, rather than 1 single Query<T>() (or whatever) with both the update and select, have those be in 2 separate functions (which can still be called from the same repo method or w/e).

  • I tried 1) and it didn't work. I get an error: [17:32:21] Error while executing SQL query on database 'test': near "SELECT": syntax error 2) Don't know what you mean by ORM/SQLData Connection. Again, I don't know why it has to be in two separately done queries. I don't know why I can't just do it in one query. – rumpled105 May 06 '17 at 00:36
0

SQLiteStudio - by default - executes only current query (currently under the cursor). Please try selecting both queries (with mouse, or with Ctrl+a) and then hit Execute. You can change this default behavior in options.

Googie
  • 5,742
  • 2
  • 19
  • 31