SQLite in memory database doesn't have EXIST IF

Viewed 46

I had sql query:


IF EXISTS(SELECT 1 FROM Amount WHERE ID = 1 AND ClientId IS NULL) 
   BEGIN
        UPDATE Amount SET Price = 11 WHERE ID = 1 AND ClientId IS NULL
        PRINT 'Updated'
  END
ELSE 
    BEGIN
         INSERT INTO Amount (ID, Price, ClientId) VALUES(1, 11, NULL)
         PRINT 'Inserted'
    END

I wanted to write test for this script, so I used sqlLite package for that:

_connection = new SqliteConnection("DataSource=InMemorySample;Mode=Memory;Cache=Shared");
_connection.Open();      
var updateCommand = _connection.CreateCommand();
updateCommand.CommandText = script;
updateCommand.ExecuteNonQuery();

However I get error: SQLite Error 1: 'near "IF": syntax error'. How should sql look so that i could be tested with sql? Or maybe it is possible to use SqlConnection instead SqlLiteConnection for in memory database?

0 Answers
Related