public void sqlServerDataBase_ConnectWithFactoryMethod_ReturnQueryResult(string ip, string port, string nameDataBase, string serverInstance, string username, string password, string engine, string query) { DataBaseFactory factory = new DataBaseFactory(); InterfaceDatabase dataBase = factory.createInstanceDataBase(ip, port, nameDataBase, serverInstance, username, password, engine); dataBase.openConnection(); string result = dataBase.executeQuery(query); dataBase.closeConnection(); Console.Write(result); }
//8 private string executeQueryInDatabase(InterfaceDatabase iNterfaceDatabase, int integrationId) { string recoverQueryId = "SELECT QueryId FROM dbo.Integrations where IntegrationId=" + integrationId; DataTable table = DataTable(recoverQueryId); int queryId = Convert.ToInt32(table.Rows[0]["QueryId"]); string query = "SELECT dbo.Queries.Query, dbo.QueryParameters.Name, dbo.QueryParameters.Value FROM dbo.Queries CROSS JOIN dbo.QueryParameters" + " where QueryParameters.IntegrationId=" + integrationId + " and Queries.QueryId=" + queryId; table = DataTable(query); string queryToDatabase = ReplaceQueryParameters(table); iNterfaceDatabase.openConnection(); string resultQuery = iNterfaceDatabase.executeQuery(queryToDatabase); iNterfaceDatabase.closeConnection(); string nameIntegration = ReturnNameIntegration(integrationId); return(resultQuery + "$" + nameIntegration); }
//7 private string obtainDatabaseParameters(int integrationId) { DataBaseFactory dataBase = new DataBaseFactory(); string query = "SELECT dbo.DatabaseParameters.Ip, dbo.DatabaseParameters.Port, dbo.DatabaseParameters.Instance, dbo.DatabaseParameters.Name, dbo.DatabaseParameters.Username," + " dbo.DatabaseParameters.Password, dbo.Engines.Name AS NameEngine, dbo.Integrations.IntegrationId" + " FROM dbo.DatabaseParameters INNER JOIN" + " dbo.Engines ON dbo.DatabaseParameters.EngineId = dbo.Engines.EngineId INNER JOIN" + " dbo.Integrations ON dbo.DatabaseParameters.DatabaseParametersId = dbo.Integrations.DatabaseParametersId" + " where IntegrationId =" + integrationId; DataTable table = DataTable(query); string instance = (Convert.ToString(table.Rows[0]["Instance"]) != null) ? decrypt.decryptData(Convert.ToString(table.Rows[0]["Instance"])) : ""; string port = (Convert.ToString(table.Rows[0]["Port"]) != null) ? decrypt.decryptData(Convert.ToString(table.Rows[0]["Port"])) : ""; string password = (Convert.ToString(table.Rows[0]["Password"]) != null) ? decrypt.decryptData(Convert.ToString(table.Rows[0]["Password"])) : ""; InterfaceDatabase iNterfaceDatabase = dataBase.createInstanceDataBase(decrypt.decryptData(Convert.ToString(table.Rows[0]["Ip"])), port, decrypt.decryptData(Convert.ToString(table.Rows[0]["Name"])), instance, decrypt.decryptData(Convert.ToString(table.Rows[0]["Username"])), password, Convert.ToString(table.Rows[0]["NameEngine"]), this); return(executeQueryInDatabase(iNterfaceDatabase, integrationId)); }