fix not closing the db connection after opening

This commit is contained in:
Jeremy Wu 2019-10-03 08:09:11 +10:00
parent 1ed7d34200
commit f4d762c19b

View file

@ -27,22 +27,27 @@ namespace Wox.Plugin.BrowserBookmark
if (string.IsNullOrEmpty(PlacesPath) || !File.Exists(PlacesPath)) if (string.IsNullOrEmpty(PlacesPath) || !File.Exists(PlacesPath))
return new List<Bookmark>(); return new List<Bookmark>();
var bookmarList = new List<Bookmark>();
// create the connection string and init the connection // create the connection string and init the connection
string dbPath = string.Format(dbPathFormat, PlacesPath); string dbPath = string.Format(dbPathFormat, PlacesPath);
var dbConnection = new SQLiteConnection(dbPath); using (var dbConnection = new SQLiteConnection(dbPath))
{
// Open connection to the database file and execute the query // Open connection to the database file and execute the query
dbConnection.Open(); dbConnection.Open();
var reader = new SQLiteCommand(queryAllBookmarks, dbConnection).ExecuteReader(); var reader = new SQLiteCommand(queryAllBookmarks, dbConnection).ExecuteReader();
// return results in List<Bookmark> format // return results in List<Bookmark> format
return reader.Select(x => new Bookmark() bookmarList = reader.Select(x => new Bookmark()
{ {
Name = (x["title"] is DBNull) ? string.Empty : x["title"].ToString(), Name = (x["title"] is DBNull) ? string.Empty : x["title"].ToString(),
Url = x["url"].ToString() Url = x["url"].ToString()
}).ToList(); }).ToList();
} }
return bookmarList;
}
/// <summary> /// <summary>
/// Path to places.sqlite /// Path to places.sqlite
/// </summary> /// </summary>