public void CreateWorkspace(Workspace workspace) { using (SQLiteConnection connection = new SQLiteConnection(ConnectionString)) { SQLiteCommand command = new SQLiteCommand(INSERT_WORKSPACE_COMMAND, connection); command.Parameters.AddWithValue("@WorkspaceKey", workspace.Key); command.Parameters.AddWithValue("@Path", workspace.Path); try { connection.Open(); command.ExecuteNonQuery(); } finally { command.Dispose(); connection.Close(); } } }
public Workspace GetWorkspace(string key) { using (SQLiteConnection connection = new SQLiteConnection(ConnectionString)) { SQLiteCommand command = new SQLiteCommand(GET_WORKSPACE_COMMAND, connection); command.Parameters.AddWithValue("@WorkspaceKey", key); SQLiteDataReader reader = null; try { connection.Open(); reader = command.ExecuteReader(); Workspace workspace = null; while(reader.Read()) { workspace = new Workspace(); workspace.Key = reader["WorkspaceKey"].ToString(); workspace.Path = reader["Path"].ToString(); } return workspace; } finally { if(reader != null) { reader.Close(); reader.Dispose(); } command.Dispose(); connection.Close(); } } }
public List<Workspace> GetWorkspaces() { using (SQLiteConnection connection = new SQLiteConnection(ConnectionString)) { SQLiteCommand command = new SQLiteCommand(GETALL_WORKSPACE_COMMAND, connection); SQLiteDataReader reader = null; try { connection.Open(); reader = command.ExecuteReader(); List<Workspace> workspaces = new List<Workspace>(); while (reader.Read()) { Workspace workspace = new Workspace() { Key = reader["WorkspaceKey"].ToString(), Path = reader["Path"].ToString() }; workspaces.Add(workspace); } return workspaces; } finally { if (reader != null) { reader.Close(); reader.Dispose(); } command.Dispose(); connection.Close(); } } }
public Dictionary<string, Workspace> GetWorkspaces() { string connection_string = CONNECTION_STRING.Replace("$(ASSEMBLY_PATH)", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); Dictionary<string, Workspace> results = new Dictionary<string, Workspace>(); using (SQLiteConnection connection = new SQLiteConnection(connection_string)) { SQLiteCommand command = new SQLiteCommand(SELECT_ALL_QUERY, connection); connection.Open(); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) { Workspace workspace = new Workspace(); workspace.ID = Convert.ToInt32(reader["ID"]); workspace.Key = Convert.ToString(reader["Key"]); workspace.Path = Convert.ToString(reader["Path"]); results.Add(workspace.Key, workspace); } reader.Close(); connection.Close(); connection.Dispose(); } return results; }