Exemple #1
0
/*
 * Reconnect to the server.  If dbname is not NULL, use that database,
 * else the one associated with the archive handle.  If username is
 * not NULL, use that user name, else the one from the handle.  If
 * both the database and the user match the existing connection already,
 * nothing will be done.
 *
 * Returns 1 in any case.
 */
int
ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *username)
{
	PGconn	   *newConn;
	const char *newdbname;
	const char *newusername;

	if (!dbname)
		newdbname = PQdb(AH->connection);
	else
		newdbname = dbname;

	if (!username)
		newusername = PQuser(AH->connection);
	else
		newusername = username;

	/* Let's see if the request is already satisfied */
	if (strcmp(newdbname, PQdb(AH->connection)) == 0 &&
		strcmp(newusername, PQuser(AH->connection)) == 0)
		return 1;

	newConn = _connectDB(AH, newdbname, newusername);

	PQfinish(AH->connection);
	AH->connection = newConn;

	return 1;
}
Exemple #2
0
   INT32 expRoutine::run()
   {
      INT32 rc = SDB_OK ;
      sdbConnectionHandle hConn = SDB_INVALID_HANDLE ;

      rc = _connectDB(hConn) ;
      if ( SDB_OK != rc )
      {
         cerr << "failed to connect to " << _options.hostName() << ":"
              << _options.svcName() << endl ;
         goto error ;
      }
      PD_LOG ( PDINFO, "Connect to %s:%s", 
               _options.hostName().c_str(), _options.svcName().c_str() );

      rc = _clSet.parse(hConn) ;
      if ( SDB_OK != rc )
      {
         PD_LOG ( PDERROR, "Failed to parse collection set, rc = %d", rc ) ;
         goto error ;
      }

      if ( _options.hasGenConf() )
      {
         rc = _options.writeToConf( _clSet ) ;
         if ( SDB_OK != rc )
         {
            cerr << "Failed to write configure-file" << endl ;
            PD_LOG ( PDERROR, "Failed to write configure-file, rc = %d", rc ) ;
            goto error ;
         }
         goto done ;
      }

      rc = _export( hConn ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG ( PDERROR, "Failed to export collections, rc = %d", rc ) ;
         goto error ;
      }

   done :
      if ( SDB_INVALID_HANDLE != hConn )
      {
         sdbDisconnect (hConn) ;
         sdbReleaseConnection(hConn) ;
      }
      return rc ;
   error :
      goto done ;
   }
Exemple #3
0
INT32 migExport::init( migExprtArg *pMigArg )
{
   INT32 rc = SDB_OK ;

   _pMigArg = pMigArg ;

   rc = _connectDB() ;
   if ( rc )
   {
      PD_LOG ( PDERROR, "Failed to connect database, rc=%d", rc ) ;
      goto error ;
   }

   // open output file
   rc = ossOpen ( _pMigArg->pFile,
                  OSS_REPLACE | OSS_WRITEONLY | OSS_EXCLUSIVE,
                  OSS_RU | OSS_WU | OSS_RG,
                  _file ) ;
   if ( rc )
   {
      PD_LOG ( PDERROR, "Failed to open file %s, rc = %d",
               _pMigArg->pFile, rc ) ;
      goto error ;
   }
   _isOpen = TRUE ;

   if ( _pMigArg->delChar == _pMigArg->delField )
   {
      rc = SDB_INVALIDARG ;
      PD_LOG ( PDERROR, "delchar does not like delfield" ) ;
      goto error ;
   }
   else if ( MIG_STR_SPACE == _pMigArg->delChar )
   {
      rc = SDB_INVALIDARG ;
      PD_LOG ( PDERROR, "delchar can not be a tab" ) ;
      goto error ;
   }
   else if ( MIG_STR_TABLE == _pMigArg->delChar )
   {
      rc = SDB_INVALIDARG ;
      PD_LOG ( PDERROR, "delchar can not be a space" ) ;
      goto error ;
   }

   if ( _pMigArg->delField == _pMigArg->delRecord )
   {
      rc = SDB_INVALIDARG ;
      PD_LOG ( PDERROR, "delfield does not like delrecord" ) ;
      goto error ;
   }
   else if ( MIG_STR_TABLE == _pMigArg->delField )
   {
      rc = SDB_INVALIDARG ;
      PD_LOG ( PDERROR, "delfield can not be a tab" ) ;
      goto error ;
   }
   else if ( MIG_STR_SPACE == _pMigArg->delField )
   {
      rc = SDB_INVALIDARG ;
      PD_LOG ( PDERROR, "delfield can not be a space" ) ;
      goto error ;
   }

   if ( _pMigArg->delRecord == _pMigArg->delChar )
   {
      rc = SDB_INVALIDARG ;
      PD_LOG ( PDERROR, "delrecord does not like delchar" ) ;
      goto error ;
   }
   else if ( MIG_STR_TABLE == _pMigArg->delRecord )
   {
      rc = SDB_INVALIDARG ;
      PD_LOG ( PDERROR, "delrecord can not be a tab" ) ;
      goto error ;
   }
   else if ( MIG_STR_SPACE == _pMigArg->delRecord )
   {
      rc = SDB_INVALIDARG ;
      PD_LOG ( PDERROR, "delrecord can not be a space" ) ;
      goto error ;
   }

   rc = _decodeBson.init( _pMigArg->delChar, _pMigArg->delField,
                          _pMigArg->includeBinary, _pMigArg->includeRegex ) ;
   if ( rc )
   {
      PD_LOG ( PDERROR, "Failed to call init, rc=%d", rc ) ;
      goto error ;
   }

   if ( _pMigArg->pFields )
   {
      rc = _decodeBson.parseFields( _pMigArg->pFields,
                                    ossStrlen( _pMigArg->pFields ) ) ;
      if ( rc )
      {
         PD_LOG ( PDERROR, "Failed to parse fields, rc=%d", rc ) ;
         goto error ;
      }
      rc = _writeInclude() ;
      if ( rc )
      {
         PD_LOG ( PDERROR, "Failed to call _writeInclude, rc=%d", rc ) ;
         goto error ;
      }
   }
done:
   return rc ;
error:
   goto done ;
}