rename option --data-source-url to --data-source-string v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Thu, 04 Jun 2020 00:46:00 +0200
branchv_0
changeset 47 428c278af4be
parent 46 85e6dc1853ee
child 48 c83119110c7b
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.
bash-completion.sh
src/CLIParser.h
src/Configuration.h
src/DriverManager.cpp
src/DriverManager.h
src/SqlHandler.h
--- 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
--- 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<string_t>& 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";
 
 }
 }
--- 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<Statement> statements;
 
--- 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);
 }
 
--- 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<DataSource> 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);
 };
 
 }
--- 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
 	}