Skip to content

Commit

Permalink
Merge pull request #113 from OHDSI/sqlite-query-fix
Browse files Browse the repository at this point in the history
removed top 1 from query
  • Loading branch information
bradanton authored Aug 29, 2024
2 parents 14a22ba + e974637 commit e7f65ad
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DbBuildingSettings(string connectionString)

public int? GetBuildingId(string sourceConnectionString, string vocabularyConnectionString, Vendor vendor)
{
const string query = "SELECT TOP 1 [BuildingId] FROM [BuildingSettings] where [SourceConnectionString] = '{0}' and [VocabularyConnectionString] = '{1}' and [Vendor] = '{2}' ORDER BY [BuildingId] desc ";
const string query = "SELECT [BuildingId] FROM [BuildingSettings] where [SourceConnectionString] = '{0}' and [VocabularyConnectionString] = '{1}' and [Vendor] = '{2}' ORDER BY [BuildingId] desc ";

using var connection = SqlConnectionHelper.OpenMssqlConnection(_connectionString);
using var cmd = SqlConnectionHelper.CreateCommand(string.Format(query, sourceConnectionString, vocabularyConnectionString, vendor), connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public bool AllChunksStarted(int buildingId)
using var connection = SqlConnectionHelper.OpenMssqlConnection(_connectionString);
using var transaction = connection.BeginTransaction();
var query =
$"SELECT TOP 1 Id FROM Chunk WHERE BuildingId = {buildingId} AND Started is null";
$"SELECT Id FROM Chunk WHERE BuildingId = {buildingId} AND Started is null";
using var cmd = SqlConnectionHelper.CreateCommand(query, connection, transaction);
using var reader = cmd.ExecuteReader();
while (reader.Read())
Expand All @@ -89,7 +89,7 @@ public bool AllChunksComplete(int buildingId)
using var connection = SqlConnectionHelper.OpenMssqlConnection(_connectionString);
using var transaction = connection.BeginTransaction();
var query =
$"SELECT TOP 1 Id FROM Chunk WHERE BuildingId = {buildingId} AND Ended is null";
$"SELECT Id FROM Chunk WHERE BuildingId = {buildingId} AND Ended is null";
using var cmd = SqlConnectionHelper.CreateCommand(query, connection, transaction);
using var reader = cmd.ExecuteReader();
while (reader.Read())
Expand Down Expand Up @@ -154,7 +154,7 @@ public void MarkUncompletedChunks(int buildingId, int builderId)
{
var orderBy = orderByDesc ? " ORDER BY 1 DESC" : "";
var query =
$"SELECT TOP 1 Id FROM Chunk with (updlock) WHERE BuildingId = {buildingId} AND Started is null{orderBy}";
$"SELECT Id FROM Chunk with (updlock) WHERE BuildingId = {buildingId} AND Started is null{orderBy}";

using (var cmd = SqlConnectionHelper.CreateCommand(query, connection, transaction))
{
Expand Down

0 comments on commit e7f65ad

Please sign in to comment.