private void ResolveJavaConnectionInfo(string connString, out string jdbcValue, out string jdbcDrivers) { OleDbConnectionStringBuilder sb = new OleDbConnectionStringBuilder(connString); string provider = sb.Provider.ToLower(); SQLDialect dialect = SQLDialect.Generic; if (provider == "sqloledb") { dialect = SQLDialect.Mssql; } else if (provider == "oraoledb" || provider == "msdaora") { dialect = SQLDialect.Oracle; } else { throw new NotSupportedException(string.Format("不支持此数据库", dialect.ToString())); } string dataSourceValue = sb.DataSource; string serverName = ""; string database = ""; int port = 1521; jdbcValue = ""; jdbcDrivers = ""; string userName = sb["User ID"].ToString(); string UserPwd = sb["Password"].ToString(); if (dialect == SQLDialect.Mssql) { string initialCatalog = sb["Initial Catalog"].ToString(); serverName = dataSourceValue; database = initialCatalog; port = 1433; jdbcValue = string.Format(MSSQLJdbcConnStringValueFormat , serverName , database , userName , UserPwd , port ); jdbcDrivers = MSSQLJdbcDrivers; } else if (dialect == SQLDialect.Oracle) { string[] serverInfo1 = dataSourceValue.Split('/'); string[] serverInfo2 = serverInfo1[0].Split(':'); serverName = serverInfo2[0]; database = serverInfo1[1]; port = serverInfo2.Length < 2 || string.IsNullOrEmpty(serverInfo2[1]) ? 1521 : int.Parse(serverInfo2[1]); jdbcValue = string.Format(OracleJdbcConnStringValueFormat , serverName , database , userName , UserPwd , port ); jdbcDrivers = OracleJdbcDrivers; } }
private int OnExecute(CommandLineApplication app) { if (string.IsNullOrEmpty(SQLDialect) || string.IsNullOrEmpty(Output)) { app.ShowHelp(); return(0); } var exitCode = 0; switch (SQLDialect.ToLowerInvariant()) { case "mssqlv2": #pragma warning disable 618 var mssqlV2Settings = new MsSqlStreamStoreSettings(new SqlConnectionStringBuilder { DataSource = "tcp:0.0.0.0,1433" }.ConnectionString); if (!string.IsNullOrEmpty(Schema)) { mssqlV2Settings.Schema = Schema; } if (CreateSchema) { var script = string.Join( Environment.NewLine, $@"IF NOT EXISTS ( SELECT schema_name FROM information_schema.schemata WHERE schema_name = '{Schema}' ) BEGIN EXEC sp_executesql N'CREATE SCHEMA {Schema}' END", new MsSqlStreamStore(mssqlV2Settings).GetSchemaCreationScript()); File.WriteAllText(Output, script); } else { File.WriteAllText(Output, new MsSqlStreamStore(mssqlV2Settings).GetSchemaCreationScript()); } #pragma warning restore 618 break; case "mssqlv3": var mssqlV3Settings = new MsSqlStreamStoreV3Settings(new SqlConnectionStringBuilder { DataSource = "tcp:0.0.0.0,1433" }.ConnectionString); if (!string.IsNullOrEmpty(Schema)) { mssqlV3Settings.Schema = Schema; } if (CreateSchema) { var script = string.Join( Environment.NewLine, $@"IF NOT EXISTS ( SELECT schema_name FROM information_schema.schemata WHERE schema_name = '{Schema}' ) BEGIN EXEC sp_executesql N'CREATE SCHEMA {Schema}' END", new MsSqlStreamStoreV3(mssqlV3Settings).GetSchemaCreationScript()); File.WriteAllText(Output, script); } else { File.WriteAllText(Output, new MsSqlStreamStoreV3(mssqlV3Settings).GetSchemaCreationScript()); } break; case "mysql": var mysqlSettings = new MySqlStreamStoreSettings(new MySqlConnectionStringBuilder { Server = "0.0.0.0" }.ConnectionString); if (!string.IsNullOrEmpty(Schema)) { Log.Information("The optional database schema does not apply to the mysql dialect and can be omitted: {Schema}", Schema); } File.WriteAllText(Output, new MySqlStreamStore(mysqlSettings).GetSchemaCreationScript()); break; case "postgres": var postgresSettings = new PostgresStreamStoreSettings(new NpgsqlConnectionStringBuilder { Host = "0.0.0.0" }.ConnectionString); if (!string.IsNullOrEmpty(Schema)) { postgresSettings.Schema = Schema; } if (CreateSchema) { var script = string.Join( Environment.NewLine, $"CREATE SCHEMA IF NOT EXISTS {Schema};", new PostgresStreamStore(postgresSettings).GetSchemaCreationScript() ); File.WriteAllText(Output, script); } else { File.WriteAllText(Output, new PostgresStreamStore(postgresSettings).GetSchemaCreationScript()); } break; default: Log.Error("The SQL dialect was not recognized: {SQLDialect}", SQLDialect); exitCode = 1; break; } return(exitCode); }
public static string GetSqlString(SQLDialect dialect, string defaultValue) { return(sqlList[(int)dialect] ?? defaultValue); }
public static string GetSqlString(SQLDialect dialect) { return(sqlList[(int)dialect]); }
public static string GetSqlString(SQLDialect dialect, string defaultValue) { return sqlList[(int)dialect] ?? defaultValue; }
public static string GetSqlString(SQLDialect dialect) { return sqlList[(int)dialect]; }