function TestConnection($sid)
{
    $isImport = $_POST['isImport'];
    $driver = strtolower($_POST['driver']);
    if ($isImport == 'true') {
        $importSettings = DatabaseImporterFactory::$importSettings[$driver];
        $serverName = 'localhost';
        $database = my_pligg_base_no_slash . "_external_{$sid}";
        $userName = $importSettings['user'];
        $password = $importSettings['password'];
        // controls how many tuples shown on each page
        $port = $importSettings['port'];
        $isLocal = 1;
        $linkedServerName = $database;
    } else {
        $userName = $_POST['userName'];
        $password = $_POST['password'];
        // controls how many tuples shown on each page
        $port = $_POST['port'];
        $serverName = $_POST['serverName'];
        $database = $_POST['database'];
        $isLocal = 0;
        if ($serverName == "tycho.exp.sis.pitt.edu") {
            $linkedServerName = $database;
        } else {
            $linkedServerName = my_pligg_base_no_slash . "_external_{$sid}";
        }
    }
    $serverName = $serverName ? $serverName : 'a fail host';
    $json = new stdClass();
    try {
        if ($port) {
            $dbHandler = DatabaseHandlerFactory::createDatabaseHandler($driver, $userName, $password, $database, $serverName, $port, $isLocal, $linkedServerName);
        } else {
            $dbHandler = DatabaseHandlerFactory::createDatabaseHandler($driver, $userName, $password, $database, $serverName, null, $isLocal, $linkedServerName);
        }
        $dbHandler->setDriver($driver);
        $dbHandler->getConnection();
        $_SESSION["dbHandler_{$sid}"] = serialize($dbHandler);
        $json->isSuccessful = true;
        $json->message = "Connected successfully";
        echo json_encode($json);
    } catch (Exception $e) {
        $json->isSuccessful = false;
        $json->message = $e->getMessage();
        echo json_encode($json);
    }
}
 private function cacheDistinctValues()
 {
     $queryToCleanCach = $this->prepareQueryToCleanCacheDistinctValues();
     $queryToCach = $this->prepareQueryToCacheDistinctValues();
     $dbHandler = DatabaseHandlerFactory::createDatabaseHandler("mssql", MSSQL_CQS_DB_USER, MSSQL_CQS_DB_PASSWORD, MSSQL_RC_DB_DATABASE, MSSQL_CQS_DB_HOST, MSSQL_CQS_DB_PORT, null, null);
     //var_dump($queryToCleanCach, $queryToCach, $dbHandler);
     $dataMatchingCheckerDAO = new DataMatchingCheckerDAO();
     try {
         $dataMatchingCheckerDAO->setQueryRelationshipColumnCaching($this->source->transformation, $queryToCleanCach);
         $dbHandler->ExecuteNonQuery($queryToCleanCach);
         $dataMatchingCheckerDAO->setQueryRelationshipColumnCaching($this->source->transformation, $queryToCach);
         $dbHandler->ExecuteNonQuery($queryToCach);
         $dataMatchingCheckerDAO->setSuccessRelationshipColumnCaching($this->source->transformation);
     } catch (Exception $e) {
         $dataMatchingCheckerDAO->setFailureRelationshipColumnCaching($this->source->transformation, $e->getMessage());
     }
 }
 public static function createDatabaseHandler($engine)
 {
     switch (strtolower($engine)) {
         case 'mysql':
             break;
         case 'mssql':
         case 'sql server':
             return DatabaseHandlerFactory::createDatabaseHandler($engine, MSSQL_CQS_DB_USER, MSSQL_CQS_DB_PASSWORD, MSSQL_CQS_DB_DATABASE, MSSQL_CQS_DB_HOST, MSSQL_CQS_DB_PORT, null, null);
             break;
         case 'postgresql':
             break;
         case 'oracle':
             break;
         default:
             throw new Exception('Invalid DBMS');
             break;
     }
 }
function delete_storylink($linkid)
{
    $logger = Logger::getLogger("generalLog");
    try {
        if (!is_numeric($linkid)) {
            return;
        }
        $query = "SELECT * FROM " . table_links . " WHERE link_id = '{$linkid}'";
        if (!($result = mysql_query($query))) {
            error_page(mysql_error());
        } else {
            $sql_array = mysql_fetch_object($result);
        }
        //var_dump($sql_array);
        # delete the story link
        $query = "DELETE FROM " . table_links . " WHERE link_id = '{$linkid}'";
        if (!($result = mysql_query($query))) {
            error_page(mysql_error());
        }
        # delete the story comments
        $query = "DELETE FROM " . table_comments . " WHERE comment_link_id = '{$linkid}'";
        if (!($result = mysql_query($query))) {
            error_page(mysql_error());
        }
        # delete the saved links
        $query = "DELETE FROM " . table_saved_links . " WHERE saved_link_id = '{$linkid}'";
        if (!($result = mysql_query($query))) {
            error_page(mysql_error());
        }
        # delete the story tags
        $query = "DELETE FROM " . table_tags . " WHERE tag_link_id = '{$linkid}'";
        if (!($result = mysql_query($query))) {
            error_page(mysql_error());
        }
        # delete the story trackbacks
        $query = "DELETE FROM " . table_trackbacks . " WHERE trackback_link_id = '{$linkid}'";
        if (!($result = mysql_query($query))) {
            error_page(mysql_error());
        }
        # delete the story votes
        $query = "DELETE FROM " . table_votes . " WHERE vote_link_id = '{$linkid}'";
        if (!($result = mysql_query($query))) {
            error_page(mysql_error());
        }
        # delete additional categories
        $query = "DELETE FROM " . table_additional_categories . " WHERE ac_link_id = '{$linkid}'";
        if (!($result = mysql_query($query))) {
            error_page(mysql_error());
        }
        $sid = $sql_array->link_title_url;
        # delete target database if local
        $query = "SELECT * FROM " . table_prefix . "sourceinfo_DB WHERE sid = {$sid}";
        if (!($result = mysql_query($query))) {
            error_page(mysql_error());
        } else {
            $sql_array = mysql_fetch_object($result);
            //var_dump($sql_array);
            if ($sql_array->is_local == 1) {
                // deleing the target db here.
                $dbHandler = DatabaseHandlerFactory::createDatabaseHandler($sql_array->driver, $sql_array->user_name, $sql_array->password, $sql_array->source_database, $sql_array->server_address, $sql_array->port, $sql_array->is_local, $sql_array->linked_server_name);
                $dbHandler->dropDatabase();
            }
            $queryEngine = new QueryEngine();
            $queryEngine->simpleQuery->dropLinkedServerIfExists($sql_array->linked_server_name);
        }
        //TODO Add some error checking
        //delete the sourceinfo which should triget casding deleting of all related info except cached queries and visualization stuff.
        $query = "DELETE FROM " . table_prefix . "sourceinfo WHERE sid = {$sid}";
        if (!($result = mysql_query($query))) {
            $logger->error("in admin delete story " . mysql_error());
            echo mysql_error();
        }
        //now the only thing left is Neo4J, need to delete node and all realtionships.
        $neo4JDAO = new Neo4JDAO();
        $neo4JDAO->deleteNodeBySid($sid);
        // module system hook
        $vars = array('link_id' => $linkid);
        check_actions('admin_story_delete', $vars);
    } catch (Exception $e) {
        $logger->error("in admin delete story " . $e->getMessage());
    }
}
Exemplo n.º 5
0
 public static function GetDBHandler($externalDBCredentials)
 {
     return DatabaseHandlerFactory::createDatabaseHandler($externalDBCredentials->driver, $externalDBCredentials->user_name, $externalDBCredentials->password, $externalDBCredentials->source_database, $externalDBCredentials->server_address, $externalDBCredentials->port, $externalDBCredentials->is_local, $externalDBCredentials->linked_server_name);
 }
Exemplo n.º 6
0
 /**
  * Create if not exist target database and target table.
  * @param        $logID eid of execution info table to update status
  * @return stdClass target database connection info
  */
 private function createTargetDatabaseAndTable($logID)
 {
     $this->ktrExecutorDAO->updateExecutionInfoLog($logID, "creating database if needed");
     // loggin to db
     // KTR manager has target database info.
     $databaseConnectionInfo = $this->ktrManager->getConnectionInfo();
     $dbHandler = DatabaseHandlerFactory::createDatabaseHandler($databaseConnectionInfo->engine, $databaseConnectionInfo->username, $databaseConnectionInfo->password, null, $databaseConnectionInfo->server, $databaseConnectionInfo->port, null, null);
     // DATABASE
     $dbHandler = $dbHandler->createDatabaseIfNotExist($databaseConnectionInfo->database);
     $this->ktrExecutorDAO->updateExecutionInfoLog($logID, "creating table if needed");
     // loggin to db
     // KTR manager also has target table name and columns which that table needs to have
     $tableName = $this->ktrManager->getTableName();
     $columns = $this->ktrManager->getColumns();
     // TABLE
     $dbHandler->createTableIfNotExist($tableName, $columns);
     //by this po everything went fine, so not just need to return target database connection info for future use
     return $databaseConnectionInfo;
 }