diff --git a/CsvQuery/Main.cs b/CsvQuery/Main.cs index b2e81d1..85cab7e 100644 --- a/CsvQuery/Main.cs +++ b/CsvQuery/Main.cs @@ -98,7 +98,7 @@ public static void OnNotification(ScNotification notification) // This method is invoked whenever something is happening in notepad++. Use as: // if (notification.Header.Code == (uint)NppMsg.NPPN_xxx) {...} // (or SciMsg.SCNxxx) - Trace.TraceInformation($"Npp notification received: {notification.Header.EventType}"); + //Trace.TraceInformation($"Npp notification received: {notification.Header.EventType}"); } public static void CommandMenuInit() @@ -108,7 +108,6 @@ public static void CommandMenuInit() PluginBase.AddMenuItem("List parsed files", ListSqliteTables); PluginBase.AddMenuItem("---", null); PluginBase.AddMenuItem("&Settings", Settings.ShowDialog); - ////PluginBase.AddMenuItem("Settings file", Settings.OpenFile); PluginBase.AddMenuItem("&About", AboutCsvQuery); } diff --git a/CsvQuery/Tools/DataStorageBase.cs b/CsvQuery/Tools/DataStorageBase.cs index d91a240..6b4f688 100644 --- a/CsvQuery/Tools/DataStorageBase.cs +++ b/CsvQuery/Tools/DataStorageBase.cs @@ -21,6 +21,7 @@ public void SetActiveTab(IntPtr bufferId) _currentActiveBufferId = bufferId; } } + public abstract string SaveData(IntPtr bufferId, List data, bool? hasHeader); public List ExecuteQuery(string query) => ExecuteQuery(query, false); public List ExecuteQueryWithColumnNames(string query) => ExecuteQuery(query, true); @@ -38,13 +39,13 @@ protected string GetOrAllocateTableName(IntPtr bufferId) if (_createdTables.ContainsKey(bufferId)) { tableName = _createdTables[bufferId]; - ExecuteNonQuery("DROP TABLE IF EXISTS " + tableName); } else { tableName = "T" + ++_lastCreatedTableName; _createdTables.Add(bufferId, tableName); } + ExecuteNonQuery("DROP TABLE IF EXISTS " + tableName); return tableName; } } diff --git a/CsvQuery/Tools/MssqlDataStorage.cs b/CsvQuery/Tools/MssqlDataStorage.cs index 5be8765..f1f2cff 100644 --- a/CsvQuery/Tools/MssqlDataStorage.cs +++ b/CsvQuery/Tools/MssqlDataStorage.cs @@ -53,14 +53,13 @@ public string SaveData(IntPtr bufferId, List data, bool? hasHeader) if (_createdTables.ContainsKey(bufferId)) { tableName = _createdTables[bufferId]; - ExecuteNonQuery("DROP TABLE IF EXISTS " + tableName); } else { tableName = "T" + ++_lastCreatedTableName; - ExecuteNonQuery("DROP TABLE IF EXISTS " + tableName); _createdTables.Add(bufferId, tableName); } + ExecuteNonQuery($"IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{tableName}' AND TABLE_SCHEMA = 'dbo') DROP TABLE dbo.{tableName}"); var columnTypes = CsvAnalyzer.DetectColumnTypes(data, hasHeader);