Skip to content

Commit 447ce9c

Browse files
author
长安员外
committed
Add MariaDB and SQLite support
1 parent 5cde827 commit 447ce9c

27 files changed

Lines changed: 274 additions & 57 deletions
11.5 KB
Loading
23.6 KB
Loading

SqlAnalyzer.App/Controls/BlueIcon.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ void Ellipse(double x, double y, double width, double height, bool fill = false)
9797
break;
9898
}
9999
goto case "connection";
100+
case "mariadblogo":
101+
if (TryDrawBitmapLogo(context, "mariadb-logo-vertical-blue.png", R(2.2, 2.0, 19.6, 20.0)))
102+
{
103+
break;
104+
}
105+
goto case "connection";
106+
case "sqlitelogo":
107+
if (TryDrawBitmapLogo(context, "sqlite-icon.png", R(3.4, 2.0, 17.2, 20.0)))
108+
{
109+
break;
110+
}
111+
goto case "connection";
100112
case "sqlserverlogo":
101113
if (TryDrawSvgLogo(context, "microsoftsqlserver.svg", R(2.2, 2.2, 19.6, 19.6), AccentBrush))
102114
{

SqlAnalyzer.App/Localization/en-US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"Notes": "Notes",
9090
"Server": "Server",
9191
"Database": "Database / SID / Service",
92+
"DatabaseFile": "Database File",
9293
"Schema": "Schema",
9394
"DatabaseConnection": "Database Connection",
9495
"CapabilityLevel": "Capability Level",

SqlAnalyzer.App/Localization/zh-CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"Notes": "备注",
9090
"Server": "服务器",
9191
"Database": "数据库 / SID / Service",
92+
"DatabaseFile": "数据库文件",
9293
"Schema": "模式 / Schema",
9394
"DatabaseConnection": "数据库连接",
9495
"CapabilityLevel": "能力级别",

SqlAnalyzer.App/Models/ResultSetViewItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private static string BuildDateLiteral(string providerName, DateTime dateTime, b
248248
{
249249
"oracle" => $"to_date('{dateTime:yyyy-MM-dd}', 'YYYY-MM-DD')",
250250
"postgresql" or "kingbasees" => $"date '{dateTime:yyyy-MM-dd}'",
251-
"mysql" => $"STR_TO_DATE('{dateTime:yyyy-MM-dd}', '%Y-%m-%d')",
251+
"mysql" or "mariadb" => $"STR_TO_DATE('{dateTime:yyyy-MM-dd}', '%Y-%m-%d')",
252252
"sqlserver" => $"cast('{dateTime:yyyy-MM-dd}' as date)",
253253
_ => $"'{dateTime:yyyy-MM-dd}'"
254254
};
@@ -258,7 +258,7 @@ private static string BuildDateLiteral(string providerName, DateTime dateTime, b
258258
{
259259
"oracle" => $"to_timestamp('{dateTime:yyyy-MM-dd HH:mm:ss.fff}', 'YYYY-MM-DD HH24:MI:SS.FF3')",
260260
"postgresql" or "kingbasees" => $"timestamp '{dateTime:yyyy-MM-dd HH:mm:ss.fff}'",
261-
"mysql" => $"STR_TO_DATE('{dateTime:yyyy-MM-dd HH:mm:ss.fff}', '%Y-%m-%d %H:%i:%s.%f')",
261+
"mysql" or "mariadb" => $"STR_TO_DATE('{dateTime:yyyy-MM-dd HH:mm:ss.fff}', '%Y-%m-%d %H:%i:%s.%f')",
262262
"sqlserver" => $"cast('{dateTime:yyyy-MM-dd HH:mm:ss.fff}' as datetime2)",
263263
_ => $"'{dateTime:yyyy-MM-dd HH:mm:ss.fff}'"
264264
};

SqlAnalyzer.App/Models/UiTextSet.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public sealed class UiTextSet
9292
public string Notes { get; init; } = string.Empty;
9393
public string Server { get; init; } = string.Empty;
9494
public string Database { get; init; } = string.Empty;
95+
public string DatabaseFile { get; init; } = string.Empty;
9596
public string Schema { get; init; } = string.Empty;
9697
public string DatabaseConnection { get; init; } = string.Empty;
9798
public string CapabilityLevel { get; init; } = string.Empty;

SqlAnalyzer.App/Services/ConnectionCenterController.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ public void ApplyProviderSelection(ConnectionProfile profile, DatabaseProviderDe
162162
profile.Port = GetDefaultPort(provider.Name) ?? 0;
163163
}
164164

165+
if (string.Equals(provider.Name, "SQLite", StringComparison.OrdinalIgnoreCase))
166+
{
167+
profile.Port = 0;
168+
profile.AuthenticationMode = string.Empty;
169+
profile.Server = string.Empty;
170+
profile.UserName = string.Empty;
171+
profile.Password = string.Empty;
172+
profile.EncryptedPassword = string.Empty;
173+
profile.SavePassword = false;
174+
return;
175+
}
176+
165177
if (string.IsNullOrWhiteSpace(profile.AuthenticationMode))
166178
{
167179
profile.AuthenticationMode = "Default";
@@ -189,6 +201,7 @@ public ConnectionEditorState HandleSelectionChanged(MainWindowViewModel viewMode
189201
return providerName.ToLowerInvariant() switch
190202
{
191203
"mysql" => 3306,
204+
"mariadb" => 3306,
192205
"sqlserver" => 1433,
193206
"postgresql" => 5432,
194207
"kingbasees" => 54321,

SqlAnalyzer.App/Services/ConnectionProfileUtilities.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public static class ConnectionProfileUtilities
1313
{
1414
"oracle" => 1521,
1515
"mysql" => 3306,
16+
"mariadb" => 3306,
1617
"sqlserver" => 1433,
1718
"postgresql" => 5432,
1819
"kingbasees" => 54321,
@@ -28,6 +29,7 @@ public static IReadOnlyList<string> GetAuthenticationModeOptions(string? provide
2829
{
2930
"oracle" => new[] { "Default", "SYSDBA", "SYSOPER" },
3031
"sqlserver" => new[] { "Default", "IntegratedSecurity" },
32+
"sqlite" => Array.Empty<string>(),
3133
_ => new[] { "Default" }
3234
};
3335
}
@@ -124,6 +126,11 @@ public static void CopyValues(ConnectionProfile target, ConnectionProfile source
124126

125127
public static string BuildIdentityEndpoint(ConnectionProfile profile)
126128
{
129+
if (string.Equals(profile.ProviderName, "SQLite", StringComparison.OrdinalIgnoreCase))
130+
{
131+
return profile.Database ?? string.Empty;
132+
}
133+
127134
if (string.Equals(profile.ProviderName, "Oracle", StringComparison.OrdinalIgnoreCase))
128135
{
129136
if (string.Equals(profile.OracleConnectionMode, "Tns", StringComparison.OrdinalIgnoreCase))
@@ -245,6 +252,18 @@ public static void ApplyProviderSelection(ConnectionProfile profile, DatabasePro
245252
profile.Port = GetDefaultPort(provider.Name) ?? 0;
246253
}
247254

255+
if (string.Equals(provider.Name, "SQLite", StringComparison.OrdinalIgnoreCase))
256+
{
257+
profile.Port = 0;
258+
profile.AuthenticationMode = string.Empty;
259+
profile.Server = string.Empty;
260+
profile.UserName = string.Empty;
261+
profile.Password = string.Empty;
262+
profile.EncryptedPassword = string.Empty;
263+
profile.SavePassword = false;
264+
return;
265+
}
266+
248267
if (string.IsNullOrWhiteSpace(profile.AuthenticationMode))
249268
{
250269
profile.AuthenticationMode = "Default";

SqlAnalyzer.App/Services/SchemaSelection.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ public static string ResolvePreferred(ConnectionProfile? profile, IEnumerable<st
4242
}
4343
}
4444

45+
if (string.Equals(profile.ProviderName, "SQLite", StringComparison.OrdinalIgnoreCase))
46+
{
47+
string? match = orderedSchemas.FirstOrDefault(item => string.Equals(item, "main", StringComparison.OrdinalIgnoreCase));
48+
if (!string.IsNullOrWhiteSpace(match))
49+
{
50+
return match;
51+
}
52+
}
53+
4554
return string.Empty;
4655
}
4756

@@ -81,10 +90,11 @@ public static string ResolveDocumentEffectiveSchema(EditorDocument document, Con
8190

8291
return profile.ProviderName switch
8392
{
84-
"MySql" => profile.Database?.Trim() ?? string.Empty,
93+
"MySql" or "MariaDB" => profile.Database?.Trim() ?? string.Empty,
8594
"PostgreSql" or "KingbaseES" => "public",
8695
"Oracle" or "Dameng" => profile.UserName?.Trim() ?? string.Empty,
8796
"SqlServer" => "dbo",
97+
"SQLite" => "main",
8898
_ => string.Empty
8999
};
90100
}

0 commit comments

Comments
 (0)