# HG changeset patch # User František Kučera # Date 1591224360 -7200 # Node ID 428c278af4bea2aaa37274980d4ebe4d5ceee76c # Parent 85e6dc1853ee3d0ec8c6a63a5ad6c42fed95f18d rename option --data-source-url to --data-source-string In some implementations like JDBC, the connection string is URL, but in ODBC the string is not formally URL, so it is better to use more general term „data source string“ instead of URL. - data source name (DSN) = name of a pre-configured database connection that should be looked-up in configuration and used - data source string (connection string) = arbitrary string containing (in certain encoding which might and might not be URL) all needed parameters (e.g. server name + port + user name + password) Name and string might sometimes be also combined: in ODBC we can e.g. connect to a string: DSN=relpipe;someParameter=foo;someOther=bar which will lookup configuration for the „relpipe“ data source and will combine it with given parameters. diff -r 85e6dc1853ee -r 428c278af4be bash-completion.sh --- a/bash-completion.sh Thu Jun 04 00:03:37 2020 +0200 +++ b/bash-completion.sh Thu Jun 04 00:46:00 2020 +0200 @@ -33,7 +33,7 @@ "boolean" ) - DATA_SOURCE_URL=( + DATA_SOURCE_STRING=( "Driver=SQLite3;Database=file::memory:" "Driver=SQLite3;Database=file:temp-relpipe.sqlite" "Driver=SQLite3;Database=file:/tmp/relpipe.sqlite" @@ -48,7 +48,7 @@ elif [[ "$w1" == "--copy-renamed" && "x$w0" == "x" ]]; then COMPREPLY=("'.+'") elif [[ "$w2" == "--copy-renamed" && "x$w0" == "x" ]]; then COMPREPLY=("'copy_of_\$0'") elif [[ "$w1" == "--data-source-name" ]]; then COMPREPLY=($(compgen -W "$(_relpipe_tr_sql_completion_dsn)" -- "$w0")) - elif [[ "$w1" == "--data-source-url" ]]; then COMPREPLY=($(compgen -W "${DATA_SOURCE_URL[*]}" -- "$w0")) + elif [[ "$w1" == "--data-source-string" ]]; then COMPREPLY=($(compgen -W "${DATA_SOURCE_STRING[*]}" -- "$w0")) else OPTIONS=( "--relation" @@ -58,7 +58,7 @@ "--copy-renamed" "--list-data-sources" "--data-source-name" - "--data-source-url" + "--data-source-string" ) COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0")) fi diff -r 85e6dc1853ee -r 428c278af4be src/CLIParser.h --- a/src/CLIParser.h Thu Jun 04 00:03:37 2020 +0200 +++ b/src/CLIParser.h Thu Jun 04 00:46:00 2020 +0200 @@ -53,7 +53,7 @@ static const string_t OPTION_COPY; static const string_t OPTION_COPY_RENAMED; static const string_t OPTION_DATA_SOURCE_NAME; - static const string_t OPTION_DATA_SOURCE_URL; + static const string_t OPTION_DATA_SOURCE_STRING; static const string_t OPTION_LIST_DATA_SOURCES; Configuration parse(const std::vector& arguments) { @@ -82,15 +82,15 @@ c.copyRelations.push_back({readNext(arguments, i), readNext(arguments, i), true}); } else if (option == OPTION_DATA_SOURCE_NAME) { c.dataSourceName = readNext(arguments, i); - } else if (option == OPTION_DATA_SOURCE_URL) { - c.dataSourceURL = readNext(arguments, i); + } else if (option == OPTION_DATA_SOURCE_STRING) { + c.dataSourceString = readNext(arguments, i); } else if (option == OPTION_LIST_DATA_SOURCES) { c.listDataSources = true; } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); } addQuery(c, currentQuery); // last relation - if (c.dataSourceName.size() && c.dataSourceURL.size()) throw relpipe::cli::RelpipeCLIException(L"Specify data source name or data source URL, not both.", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); + if (c.dataSourceName.size() && c.dataSourceString.size()) throw relpipe::cli::RelpipeCLIException(L"Specify data source name or data source string, not both.", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); return c; } @@ -110,7 +110,7 @@ const string_t CLIParser::OPTION_COPY_RENAMED = L"--copy-renamed"; const string_t CLIParser::OPTION_LIST_DATA_SOURCES = L"--list-data-sources"; const string_t CLIParser::OPTION_DATA_SOURCE_NAME = L"--data-source-name"; -const string_t CLIParser::OPTION_DATA_SOURCE_URL = L"--data-source-url"; +const string_t CLIParser::OPTION_DATA_SOURCE_STRING = L"--data-source-string"; } } diff -r 85e6dc1853ee -r 428c278af4be src/Configuration.h --- a/src/Configuration.h Thu Jun 04 00:03:37 2020 +0200 +++ b/src/Configuration.h Thu Jun 04 00:46:00 2020 +0200 @@ -89,7 +89,7 @@ relpipe::writer::string_t dataSourceName; - relpipe::writer::string_t dataSourceURL; + relpipe::writer::string_t dataSourceString; std::vector statements; diff -r 85e6dc1853ee -r 428c278af4be src/DriverManager.cpp --- a/src/DriverManager.cpp Thu Jun 04 00:03:37 2020 +0200 +++ b/src/DriverManager.cpp Thu Jun 04 00:46:00 2020 +0200 @@ -69,11 +69,11 @@ (SQLCHAR*) dataSourceNameBytes.c_str(), SQL_NTS, (SQLCHAR*) userNameBytes.c_str(), SQL_NTS, (SQLCHAR*) passwordBytes.c_str(), SQL_NTS); - if (OdbcCommon::isNotSuccessful(result)) throw SqlException(L"Unable to connect to DSN: " + dataSourceName, result, SQL_HANDLE_DBC, connection, true); + if (OdbcCommon::isNotSuccessful(result)) throw SqlException(L"Unable to connect through DSN: " + dataSourceName, result, SQL_HANDLE_DBC, connection, true); return new Connection(connection); } -Connection* DriverManager::getConnectionByURL(relpipe::reader::string_t connectionString) { +Connection* DriverManager::getConnectionByString(relpipe::reader::string_t connectionString) { SQLHDBC connection = OdbcCommon::allocateHandle(SQL_HANDLE_DBC, environment); char completeConnectionString[SQL_MAX_OPTION_STRING_LENGTH]; memset(completeConnectionString, 0, sizeof (completeConnectionString)); @@ -82,7 +82,7 @@ (SQLCHAR*) convertor.to_bytes(connectionString).c_str(), SQL_NTS, (SQLCHAR*) completeConnectionString, sizeof (completeConnectionString), &completeConnectionStringLength, SQL_DRIVER_NOPROMPT); - if (OdbcCommon::isNotSuccessful(result)) throw SqlException(L"Unable to connect to URL: " + connectionString, result, SQL_HANDLE_DBC, connection, true); + if (OdbcCommon::isNotSuccessful(result)) throw SqlException(L"Unable to connect through string: " + connectionString, result, SQL_HANDLE_DBC, connection, true); return new Connection(connection); } diff -r 85e6dc1853ee -r 428c278af4be src/DriverManager.h --- a/src/DriverManager.h Thu Jun 04 00:03:37 2020 +0200 +++ b/src/DriverManager.h Thu Jun 04 00:46:00 2020 +0200 @@ -54,7 +54,7 @@ virtual ~DriverManager(); std::vector getDataSources(); Connection* getConnectionByDSN(relpipe::reader::string_t dataSourceName, relpipe::reader::string_t userName = L"", relpipe::reader::string_t password = L""); - Connection* getConnectionByURL(relpipe::reader::string_t connectionString); + Connection* getConnectionByString(relpipe::reader::string_t connectionString); }; } diff -r 85e6dc1853ee -r 428c278af4be src/SqlHandler.h --- a/src/SqlHandler.h Thu Jun 04 00:03:37 2020 +0200 +++ b/src/SqlHandler.h Thu Jun 04 00:46:00 2020 +0200 @@ -162,8 +162,8 @@ Connection* getConnection() { if (configuration.dataSourceName.size()) return driverManager->getConnectionByDSN(configuration.dataSourceName); - else if (configuration.dataSourceURL.size()) return driverManager->getConnectionByURL(configuration.dataSourceURL); - else return driverManager->getConnectionByURL(L"Driver=SQLite3;Database=:memory:"); + else if (configuration.dataSourceString.size()) return driverManager->getConnectionByString(configuration.dataSourceString); + else return driverManager->getConnectionByString(L"Driver=SQLite3;Database=:memory:"); // SQLite is default/fallback oprion // TODO: use environmental variable to allow setting a different default }