示例#1
0
/* Open a connection to the database. */
int _connect_to_db(struct db_context_t *dbc)
{
    dbc->mysql=mysql_init(NULL);

    //FIXME: change atoi() to strtol() and check for errors
    if (!mysql_real_connect(dbc->mysql, mysql_host, mysql_user, mysql_pass, mysql_dbname, atoi(mysql_port_t), mysql_socket_t, 0))
    {
      if (mysql_errno(dbc->mysql))
      {
        LOG_ERROR_MESSAGE("Connection to database '%s' failed.", mysql_dbname);
	LOG_ERROR_MESSAGE("mysql reports: %d %s", 
                           mysql_errno(dbc->mysql), mysql_error(dbc->mysql));
      }
      return ERROR;
    }

    /* Disable AUTOCOMMIT mode for connection */
    if (mysql_real_query(dbc->mysql, "SET AUTOCOMMIT=0", 16))
    {
      LOG_ERROR_MESSAGE("mysql reports: %d %s", mysql_errno(dbc->mysql) ,
                         mysql_error(dbc->mysql));
      return ERROR;
    }

    return OK;
}
示例#2
0
char *dbt2_sql_getvalue(struct db_context_t *dbc,
		struct sql_result_t *sql_result, int field)
{
	SQLRETURN rc;
	char *tmp;
  
	tmp = NULL;
	SQLINTEGER cb_var = 0;

	if (sql_result->current_row && field < sql_result->num_fields) {
		if ((tmp = calloc(sizeof(char), sql_result->lengths[field] + 1))) {
			rc = SQLGetData(dbc->hstmt, field + 1, SQL_C_CHAR, tmp,
					sql_result->lengths[field] + 1, &cb_var);
			if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
				LOG_ODBC_ERROR(SQL_HANDLE_STMT, dbc->hstmt);
			}
		} else {
			LOG_ERROR_MESSAGE("dbt2_sql_getvalue: CALLOC FAILED for value from field=%d\n", field);
		}
#ifdef DEBUG_QUERY
	} else {
		LOG_ERROR_MESSAGE("dbt2_sql_getvalue: FIELD %d current_row %d\nQUERY --- %s\n", field, sql_result->current_row, sql_result->query);
#endif
	}
	return tmp;
}
示例#3
0
char * dbt2_sql_getvalue(struct db_context_t *dbc, struct sql_result_t * sql_result, int field)
{
  char * tmp;
  
  tmp= NULL;

  if (sql_result->current_row && field < sql_result->num_fields)
  {
    if (sql_result->current_row[field])
    {
      if ((tmp = calloc(sizeof(char), sql_result->lengths[field]+1)))
      {
        memcpy(tmp, (sql_result->current_row)[field], sql_result->lengths[field]);
      }
      else
      {
        LOG_ERROR_MESSAGE("dbt2_sql_getvalue: CALLOC FAILED for value from field=%d\n", field);
      }
    }
    else
    {
#ifdef DEBUG_QUERY
      LOG_ERROR_MESSAGE("dbt2_sql_getvalue: var[%d]=NULL\n", field);
#endif
    }
  }
  else
  {
#ifdef DEBUG_QUERY
    LOG_ERROR_MESSAGE("dbt2_sql_getvalue: POSSIBLE NULL VALUE or ERROR\n\Query: %s\nField: %d from %d", 
                       sql_result->query, field, sql_result->num_fields);
#endif
  }
  return tmp;
}
示例#4
0
int rollback_transaction(struct db_context_t *dbc)
{
      LOG_ERROR_MESSAGE("ROLLBACK INITIATED\n");

      if (mysql_real_query(dbc->mysql, "ROLLBACK", 8)) 
      {
        LOG_ERROR_MESSAGE("ROLLBACK failed. mysql reports: %d %s", 
                           mysql_errno(dbc->mysql), mysql_error(dbc->mysql));
        return ERROR;
      }
      return STATUS_ROLLBACK;
}
示例#5
0
int execute_product_detail(struct db_context_t *dbc,
	struct product_detail_t *data)
{
	char sql_cmd[512];

	PGresult *res;
	int j;

	/* Create SQL Command */
	memset(sql_cmd, 0x00, sizeof(sql_cmd));
	sprintf(sql_cmd,STMT_PRODUCT_DETAIL, data->i_id);

	/* Execute SQL Command */
	res = PQexec(dbc->conn, sql_cmd);
	if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
	{
		LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
		PQclear(res);
		return ERROR;
	}

	if (PQntuples(res) == 0)
	{
		LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
		LOG_ERROR_MESSAGE("Could not obtain produce detail\n");
		PQclear(res);
		return ERROR;
	}

	/* Get data */
	j = 0;
	strcpy(data->i_title, PQgetvalue(res, 0, j++));
	strcpy(data->a_fname, PQgetvalue(res, 0, j++));
	strcpy(data->a_lname, PQgetvalue(res, 0, j++));
	strcpy(data->i_pub_date, PQgetvalue(res, 0, j++));
	strcpy(data->i_publisher, PQgetvalue(res, 0, j++));
	strcpy(data->i_subject, PQgetvalue(res, 0, j++));
	strcpy(data->i_desc, PQgetvalue(res, 0, j++));
	data->i_image = atoll(PQgetvalue(res, 0, j++));
	data->i_cost = strtod(PQgetvalue(res, 0, j++), NULL);
	data->i_srp = strtod(PQgetvalue(res, 0, j++), NULL);
	strcpy(data->i_avail, PQgetvalue(res, 0, j++));
	strcpy(data->i_isbn, PQgetvalue(res, 0, j++));
	data->i_page = atoi(PQgetvalue(res, 0, j++));
	strcpy(data->i_backing, PQgetvalue(res, 0, j++));
	strcpy(data->i_dimensions, PQgetvalue(res, 0, j++));
	PQclear(res);

	return OK;
}
示例#6
0
bool pamLogin(const std::string& username, const std::string& password)
{
   // get path to pam helper
   FilePath pamHelperPath(server::options().authPamHelperPath());
   if (!pamHelperPath.exists())
   {
      LOG_ERROR_MESSAGE("PAM helper binary does not exist at " +
                        pamHelperPath.absolutePath());
      return false;
   }

   // form args
   std::vector<std::string> args;
   args.push_back(username);

   // options (assume priv after fork)
   core::system::ProcessOptions options;
   options.onAfterFork = assumeRootPriv;

   // run pam helper
   core::system::ProcessResult result;
   Error error = core::system::runProgram(pamHelperPath.absolutePath(),
                                          args,
                                          password,
                                          options,
                                          &result);
   if (error)
   {
      LOG_ERROR(error);
      return false;
   }

   // check for success
   return result.exitStatus == 0;
}
示例#7
0
// on Win32 open urls using our special urlopener.exe -- this is
// so that the shell exec is made out from under our windows "job"
void openUrl(const QUrl& url)
{
   // we allow default handling for  mailto and file schemes because qt
   // does custom handling for them and they aren't affected by the chrome
   //job object issue noted above
   if (url.scheme() == QString::fromAscii("mailto") ||
       url.scheme() == QString::fromAscii("file"))
   {
      QDesktopServices::openUrl(url);
   }
   else
   {
      core::system::ProcessOptions options;
      options.breakawayFromJob = true;
      options.detachProcess = true;

      std::vector<std::string> args;
      args.push_back(url.toString().toStdString());

      core::system::ProcessResult result;
      Error error = core::system::runProgram(
            desktop::options().urlopenerPath().absolutePath(),
            args,
            "",
            options,
            &result);

      if (error)
         LOG_ERROR(error);
      else if (result.exitStatus != EXIT_SUCCESS)
         LOG_ERROR_MESSAGE(result.stdErr);
   }
}
示例#8
0
		int OsalNvWrite(NvItem_t &nvItem) {
			if (nvItem.len == 0 || nvItem.len > 246)
			{
				return -1;
			}

			mtMessage_t req;

			req.cmdType = 0x21;
			req.cmdId = MT_SYS_OSAL_NV_WRITE;
			req.dataLength = 4 + nvItem.len;
			_INT_TO_BYTES_(*(req.pData), nvItem.id, 2);
			req.pData[2] = nvItem.offset;
			req.pData[3] = nvItem.len;

			for (int i=0;i<nvItem.len;i++)
			{
				req.pData[4+i] = nvItem.value[i];
			}

			uint8_t result[256];
			uint8_t *rtn = result;

			if (__MTSEND__(&req,result,256,NULL) < 0)
			{
				LOG_ERROR_MESSAGE("OsalNvWrite failed");
				return -1;
			}

			nvItem.status = *(rtn++);

			return 0;
		}
示例#9
0
		int OsalNvRead(NvItem_t &nvItem) {
			mtMessage_t req;

			req.cmdType = 0x21;
			req.cmdId = MT_SYS_OSAL_NV_READ;
			req.dataLength = 3;
			_INT_TO_BYTES_(*(req.pData), nvItem.id, 2);
			req.pData[2] = nvItem.offset;

			uint8_t result[256];
			uint8_t *rtn = result;

			if (__MTSEND__(&req,result,256,NULL) < 0)
			{
				LOG_ERROR_MESSAGE("OsalNvRead failed");
				return -1;
			}

			nvItem.status = *(rtn++);
			nvItem.len = *(rtn++);
			for (int i=0;i<nvItem.len; i++) {
				nvItem.value[i] = *(rtn++);
			}
			return 0;
		}
示例#10
0
/* Initialize ODBC environment handle and the database connect string. */
int _db_init(char *sname, char *uname, char *auth)
{
	SQLRETURN rc;

	/* Initialized the environment handle. */
	rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
	if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
	{
		LOG_ERROR_MESSAGE("alloc env handle failed");
		return W_ERROR;
	}
	
	rc = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
	if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
	{
		SQLFreeHandle(SQL_HANDLE_ENV, henv);
		printf("set env failed");
		return 0;
	}

	/* Set the database connect string, username and password. */
	strcpy(servername, sname);
	strcpy(username, uname);
	strcpy(authentication, auth);
	
	return OK;
}
示例#11
0
文件: dbc_common.c 项目: mw2q/dbt2
int rollback_transaction(struct db_context_t *dbc)
{
  LOG_ERROR_MESSAGE("ROLLBACK INITIATED\n");

  if (dbc->inTransaction)
  {
    if (sqlite3_exec(dbc->db, "ROLLBACK TRANSACTION;", NULL, NULL, NULL) != SQLITE_OK)
    {
      LOG_ERROR_MESSAGE("ROLLBACK TRANSACTION;\nsqlite reports: %d %s", sqlite3_errcode(dbc->db), sqlite3_errmsg(dbc->db));
      return ERROR;
    }
	dbc->inTransaction = 0;
  }

  return STATUS_ROLLBACK;
}
示例#12
0
int execute_order_status(struct db_context_t *dbc, struct order_status_t *data)
{
        PGresult *res;
        char stmt[512];

        int nFields;
        int i, j;

        /* Start a transaction block. */
        res = PQexec(dbc->conn, "BEGIN");
        if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
                LOG_ERROR_MESSAGE("%s", PQerrorMessage(dbc->conn));
                PQclear(res);
                return ERROR;
        }
        PQclear(res);

        /* Create the query and execute it. */
        sprintf(stmt, "SELECT * FROM order_status(%d, %d, %d, '%s')",
                data->c_id, data->c_w_id, data->c_d_id, data->c_last);
        res = PQexec(dbc->conn, stmt);
        if (!res || (PQresultStatus(res) != PGRES_COMMAND_OK &&
                PQresultStatus(res) != PGRES_TUPLES_OK)) {
                LOG_ERROR_MESSAGE("%s", PQerrorMessage(dbc->conn));
                PQclear(res);
                return ERROR;
        }
        /* first, print out the attribute names */
        nFields = PQnfields(res);
        for (i = 0; i < nFields; i++) {
            char* tmp = PQfname(res, i);
            if(g_debug) printf("%-15s", tmp);
        }
        if(g_debug) printf("\n\n");

        /* next, print out the rows */
        for (i = 0; i < PQntuples(res); i++) {
            for (j = 0; j < nFields; j++) {
                char* tmp = PQgetvalue(res, i, j);
                if(g_debug) printf("%-15s", tmp);
            }
            if(g_debug) printf("\n");
        }
        PQclear(res);

        return OK;
}
示例#13
0
int getPromoImages(	struct db_context_t *dbc,
					struct promotional_processing_t *data)
{
	int i = 0 ;
	char sql_cmd[512];

	PGresult *res;
	int j;
	
	/* Create SQL Command */
	memset( sql_cmd , 0x00 , sizeof( sql_cmd ) ) ;
	sprintf(sql_cmd,STMT_getPromoImages,
		data->i_id,
		data->i_id,
		data->i_id,
		data->i_id,
		data->i_id);

	/* Execute SQL Command */
	res = PQexec(dbc->conn, sql_cmd);
	if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
	{
		LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
		PQclear(res);
		return ERROR;
	}

	if (PQntuples(res) == 0)
	{
		LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
		LOG_ERROR_MESSAGE("Could not obtain promo images\n");
		PQclear(res);
		return ERROR;
	}

	/* Get data */
	for (i = 0;i < 5 && i < PQntuples(res);i++)
	{
		j = 0;
		data->i_related[i] = atoll(PQgetvalue(res, i, j++));
		data->i_thumbnail[i] = atoll(PQgetvalue(res, i, j++));
	}
	PQclear(res);

	return OK;
}
示例#14
0
文件: dbc_common.c 项目: mw2q/dbt2
int commit_transaction(struct db_context_t *dbc)
{
  if (dbc->inTransaction)
  {
    if (sqlite3_exec(dbc->db, "COMMIT TRANSACTION;", NULL, NULL, NULL) != SQLITE_OK)
    {
      LOG_ERROR_MESSAGE("COMMIT TRANSACTION;\nsqlite reports: %d %s", sqlite3_errcode(dbc->db), sqlite3_errmsg(dbc->db));
      return ERROR;
    }
	dbc->inTransaction = 0;
#ifdef DEBUG_QUERY
    LOG_ERROR_MESSAGE("COMMIT TRANSACTION;\n");
#endif
  }

  return OK;
}
示例#15
0
uint8_t MTSysPingProc(uint8_t *pBuf, uint8_t *returnBuffer)
{
	uint8_t SysPingRsp[SYSPINGRSP_LEN];
	ByteReverse(pBuf+SYSPINGRSP_POS, SYSPINGRSP_LEN, SysPingRsp);
	LOG_ERROR_MESSAGE("Sys ping response: %02x%02x",SysPingRsp[1],SysPingRsp[0]);
	*returnBuffer = SysPingRsp[0];
	*(returnBuffer+1) = SysPingRsp[1];
	return 0;
}
示例#16
0
int execute_stock_level(struct db_context_t *dbc, struct stock_level_t *data)
{
	char stmt[512];

        /* Create the query and execute it. */
	sprintf(stmt, "call stock_level(%d, %d, %d, @low_stock)", data->w_id, data->d_id, data->threshold);

#ifdef DEBUG_QUERY
        LOG_ERROR_MESSAGE("execute_stock_level stmt: %s\n", stmt);
#endif

        if (mysql_query(dbc->mysql, stmt))
        {
          LOG_ERROR_MESSAGE("mysql reports: %d %s", mysql_errno(dbc->mysql) ,
                            mysql_error(dbc->mysql));
          return ERROR;
        }
        return OK;
}
示例#17
0
int execute_delivery(struct db_context_t *dbc, struct delivery_t *data)
{
	char stmt[512];

	/* Create the query and execute it. */
	sprintf(stmt, "call delivery(%d, %d)",
		data->w_id, data->o_carrier_id);

#ifdef DEBUG_QUERY
        LOG_ERROR_MESSAGE("execute_delivery stmt: %s\n", stmt);
#endif
        if (mysql_query(dbc->mysql, stmt))
        {
          LOG_ERROR_MESSAGE("mysql reports: %d %s", mysql_errno(dbc->mysql) , 
                            mysql_error(dbc->mysql));
          return ERROR;
        }
	return OK;
}
示例#18
0
int integrity(struct db_context_t *dbc, struct integrity_t *data, char ** vals, int nvals)
{
	/* Input variables. */
	int w_id = data->w_id;

        struct sql_result_t result;
	char query[256];
        int W_ID=0;
 
        dbt2_init_values(vals, nvals);

	sprintf(query, INTEGRITY_1);

#ifdef DEBUG_QUERY
        LOG_ERROR_MESSAGE("INTEGRITY_1 query: %s\n",query);
#endif
        if (dbt2_sql_execute(dbc, query, &result, "INTEGRITY_1") && result.result_set)
        {
          dbt2_sql_fetchrow(dbc, &result);
          vals[W_ID] = dbt2_sql_getvalue(dbc, &result, 0); //W_ID
          dbt2_sql_close_cursor(dbc, &result);

          if (!vals[W_ID])
          {
            LOG_ERROR_MESSAGE("ERROR: W_ID is NULL for query INTEGRITY_1:\n%s\n", query);
            return -1;
          }

          if (atoi(vals[W_ID]) != w_id)
          {
            LOG_ERROR_MESSAGE("ERROR: Expect W_ID = %d Got W_ID = %d", w_id, atoi(vals[W_ID]));
            return -1;
          }
        }
        else //error
        {
          return -1;
        }

        dbt2_free_values(vals, nvals);

        return 1;
}
示例#19
0
std::vector<RVersion> enumerateRVersions(
                              std::vector<FilePath> rHomePaths,
                              bool scanForOtherVersions,
                              const FilePath& ldPathsScript,
                              const std::string& ldLibraryPath)
{
   std::vector<RVersion> rVersions;

   // scan if requested
   if (scanForOtherVersions)
   {
      // start with all of the typical script locations
      rHomePaths.push_back(FilePath("/usr/lib/R"));
      rHomePaths.push_back(FilePath("/usr/local/lib/R"));
      rHomePaths.push_back(FilePath("/opt/local/lib/R"));

      // scan /opt/R and /opt/local/R
      scanForRHomePaths(FilePath("/opt/R"), &rHomePaths);
      scanForRHomePaths(FilePath("/opt/local/R"), &rHomePaths);
   }

   // filter on existence and eliminate duplicates
   rHomePaths = removeNonExistent(rHomePaths);
   std::sort(rHomePaths.begin(), rHomePaths.end());
   rHomePaths.erase(std::unique(rHomePaths.begin(), rHomePaths.end()),
                    rHomePaths.end());

   // probe versions
   BOOST_FOREACH(const FilePath& rHomePath, rHomePaths)
   {
      // compute R script path
      FilePath rScriptPath = rHomePath.childPath("bin/R");
      if (!rScriptPath.exists())
         continue;

      std::string rDiscoveredScriptPath, rVersion, errMsg;
      core::system::Options env;
      if (detectREnvironment(rScriptPath,
                             ldPathsScript,
                             ldLibraryPath,
                             &rDiscoveredScriptPath,
                             &rVersion,
                             &env,
                             &errMsg))
      {
         RVersion version(rVersion, env);
         rVersions.push_back(version);
      }
      else
      {
         LOG_ERROR_MESSAGE("Error scanning R version at " +
                           rScriptPath.absolutePath() + ": " +
                           errMsg);
      }
   }
示例#20
0
int init_thread_pool(int PoolThreads, int TxnQSize, char *sname, char *dbname, char *uname, char *auth, char *dbport)
#endif
{
	int i;
	pthread_t ThreadID;

	/* create semaphore with initial value 0, and local to current process */
	if (sem_init(&TxnQSem, 0, 0) == -1) return FALSE;
	/* initialize mutex */
	pthread_mutex_init(&queue_mutex, NULL);
	queue_entry_condition = (struct condition_bundle_t *)
		malloc(sizeof(struct condition_bundle_t) * TxnQSize);
	for (i = 0; i < TxnQSize; i++)
	{
		queue_entry_condition[i].done_flag = 0;
		pthread_mutex_init(&queue_entry_condition[i].condition_mutex, NULL);
		pthread_cond_init(&queue_entry_condition[i].done_cv, NULL);
	}

#ifndef _SIMDB
#ifdef ODBC
	/* This should be buried under a generic database initializtion call. */
	if (db_init(sname, uname, auth) == ERROR)
	{
		return ERROR;
	}
#endif
#ifdef LIBPQ
	if (db_init(sname, dbname, uname, auth, dbport) == ERROR)
	{
		return ERROR;
	}
#endif

#endif /* _SIMDB */

	/* Create a pool of threads that connect to the database. */
	printf("Openning connections to the database.\n");
	for (i = 0; i < PoolThreads; i++)
	{
		if (pthread_create (&ThreadID, NULL, DoTxn, NULL) != 0)
		{
			LOG_ERROR_MESSAGE("error creating threadpool thread\n");
			return FALSE;
		}
		/*
		 * We need to slow down the database connection requests because
		 * they will fail if we make too many too fast.
		 */
		sleep(1);
	}
	printf("Database connections have been established.\n");
	return TRUE;
}
示例#21
0
int commit_transaction(struct db_context_t *dbc)
{

      if (mysql_real_query(dbc->mysql, "COMMIT", 6)) 
      {
        LOG_ERROR_MESSAGE("COMMIT failed. mysql reports: %d %s", 
                           mysql_errno(dbc->mysql), mysql_error(dbc->mysql));
        return ERROR;
      }
      return OK;
}
示例#22
0
// The str that is passed in should INCLUDE the " " around the value!
// (Sorry this is inconsistent with jsonLiteralEscape, but it's more efficient
// than adding double-quotes in this function)
std::string jsonLiteralUnescape(const std::string& str)
{
   json::Value value;
   if (!json::parse(str, &value) || !json::isType<std::string>(value))
   {
      LOG_ERROR_MESSAGE("Failed to unescape JS literal");
      return str;
   }

   return value.get_str();
}
示例#23
0
int dbt2_sql_execute(struct db_context_t *dbc, char * query, struct sql_result_t * sql_result, 
                       char * query_name)
{

  sql_result->result_set= NULL;
  sql_result->num_fields= 0;
  sql_result->num_rows= 0;
  sql_result->query=query;

  if (mysql_query(dbc->mysql, query))
  {
    LOG_ERROR_MESSAGE("%s: %s\nmysql reports: %d %s",query_name, query,
                            mysql_errno(dbc->mysql), mysql_error(dbc->mysql));
    return 0;
  }
  else 
  {
    sql_result->result_set = mysql_store_result(dbc->mysql);

    if (sql_result->result_set)  
    {
      sql_result->num_fields= mysql_num_fields(sql_result->result_set);
      sql_result->num_rows= mysql_num_rows(sql_result->result_set);
    }
    else  
    {
      if (mysql_field_count(dbc->mysql) == 0)
      {
        sql_result->num_rows = mysql_affected_rows(dbc->mysql);
      }
      else 
      {
         LOG_ERROR_MESSAGE("%s: %s\nmysql reports: %d %s",query_name, query,
                            mysql_errno(dbc->mysql), mysql_error(dbc->mysql));
         return 0;
      }
    }
  }

  return 1;
}
示例#24
0
int check_odbc_rc(SQLSMALLINT handle_type, SQLHANDLE handle, SQLRETURN rc)
{
	
	if (rc == SQL_SUCCESS) {
		return OK;
	} else if (rc == SQL_SUCCESS_WITH_INFO) {
		LOG_ERROR_MESSAGE("SQL_SUCCESS_WITH_INFO");
	} else if (rc == SQL_NEED_DATA) {
		LOG_ERROR_MESSAGE("SQL_NEED_DATA");
	} else if (rc == SQL_STILL_EXECUTING) {
		LOG_ERROR_MESSAGE("SQL_STILL_EXECUTING");
	} else if (rc == SQL_ERROR) {
		return ERROR;
	} else if (rc == SQL_NO_DATA) {
		LOG_ERROR_MESSAGE("SQL_NO_DATA");
	} else if (rc == SQL_INVALID_HANDLE) {
		LOG_ERROR_MESSAGE("SQL_INVALID_HANDLE");
	}
	
	return OK;
}
示例#25
0
 SyncChildProcess(const std::string& exe,
                  const std::vector<std::string>& args,
                  const ProcessOptions& options)
    : ChildProcess()
 {
    init(exe, args, options);
    if (!options.stdOutFile.empty() || !options.stdErrFile.empty())
    {
       LOG_ERROR_MESSAGE(
                "stdOutFile/stdErrFile options cannot be used with runProgram");
    }
 }
示例#26
0
int rollback_transaction(struct db_context_t *dbc)
{
    LOG_ERROR_MESSAGE("ROLLBACK INITIATED\n");

    (void)drizzle_query_str(dbc->drizzle_con, dbc->drizzle_result_set, "ROLLBACK", &drizzle_return);
    if (drizzle_return != DRIZZLE_RETURN_OK)
    {
        printf("drizzle_query ROLLBACK failed: %s\n", drizzle_con_error(dbc->drizzle_con));
        return ERROR;
    }

    return STATUS_ROLLBACK;
}
示例#27
0
int  new_order(struct db_context_t *dbc, struct new_order_t *data, char ** vals, int nvals)
{
    /* Input variables. */
    int w_id = data->w_id;
    int d_id = data->d_id;
    int c_id = data->c_id;
    int o_all_local = data->o_all_local;
    int o_ol_cnt = data->o_ol_cnt;

    int ol_i_id[15];
    int ol_supply_w_id[15];
    int ol_quantity[15];

    char query[1024];
    struct sql_result_t result;
    int i;

    /* Loop through the last set of parameters. */
    for (i = 0; i < 15; i++) {
        ol_i_id[i] = data->order_line[i].ol_i_id;
        ol_supply_w_id[i] = data->order_line[i].ol_supply_w_id;
        ol_quantity[i] = data->order_line[i].ol_quantity;
    }

    sprintf(query, NUODB_NEW_ORDER, w_id, d_id, c_id, o_all_local, o_ol_cnt,
            ol_i_id[0], ol_supply_w_id[0], ol_quantity[0],
            ol_i_id[1], ol_supply_w_id[1], ol_quantity[1],
            ol_i_id[2], ol_supply_w_id[2], ol_quantity[2],
            ol_i_id[3], ol_supply_w_id[3], ol_quantity[3],
            ol_i_id[4], ol_supply_w_id[4], ol_quantity[4],
            ol_i_id[5], ol_supply_w_id[5], ol_quantity[5],
            ol_i_id[6], ol_supply_w_id[6], ol_quantity[6],
            ol_i_id[7], ol_supply_w_id[7], ol_quantity[7],
            ol_i_id[8], ol_supply_w_id[8], ol_quantity[8],
            ol_i_id[9], ol_supply_w_id[9], ol_quantity[9],
            ol_i_id[10], ol_supply_w_id[10], ol_quantity[10],
            ol_i_id[11], ol_supply_w_id[11], ol_quantity[11],
            ol_i_id[12], ol_supply_w_id[12], ol_quantity[12],
            ol_i_id[13], ol_supply_w_id[13], ol_quantity[13],
            ol_i_id[14], ol_supply_w_id[14], ol_quantity[14]);

#ifdef DEBUG_QUERY
    LOG_ERROR_MESSAGE("NEW_ORDER_1: %s\n",query);
#endif
    if (!dbt2_sql_execute(dbc, query, &result, "NEW_ORDER"))
    {
        return 10;
    }

    return 0;
}
示例#28
0
文件: dbc_common.c 项目: mw2q/dbt2
/* Open a connection to the database. */
int _connect_to_db(struct db_context_t *dbc)
{
	int rc;

	rc = sqlite3_open(sqlite_dbname, &dbc->db);
	dbc->inTransaction = 0;
	if (rc) {
        LOG_ERROR_MESSAGE("Connection to database '%s' failed (error code %d).", sqlite_dbname, rc);
		sqlite3_close(dbc->db);
		return ERROR;
	}

    return OK;
}
示例#29
0
int sb_image_check()
{
	int fd;
	int rtnval = 0;
//	off_t offset = HAL_SB_CRC_ADDR - HAL_SB_IMG_ADDR;
	uint16_t *crc;
	uint8_t firmwareBuffer[HAL_SB_IMG_SIZE];

	fd = open(SB_FIRMWARE_PERM_PATH, O_RDWR);
	if (fd < 0)
	{
		LOG_ERROR_MESSAGE("image file open failed");
		return -1;
	}

	if (read(fd, (void *)firmwareBuffer, HAL_SB_IMG_SIZE) != HAL_SB_IMG_SIZE)
	{
		LOG_ERROR_MESSAGE("bad image size");
		rtnval = -1;
		goto exit_sb_image_check;
	}

	// basic check crc first
	crc = (uint16_t *)(firmwareBuffer + HAL_SB_CRC_ADDR - HAL_SB_IMG_ADDR);
	if (crc[0] == 0xFFFF || crc[0] == 0x0000 || crc[0] != calcCRC(firmwareBuffer))
	{
		LOG_ERROR_MESSAGE("bad image crc");
		rtnval = -1;
		goto exit_sb_image_check;
	}


	exit_sb_image_check:
	close(fd);
	return rtnval;
}
示例#30
0
int commit_transaction(struct db_context_t *dbc)
{
	PGresult *res;

	res = PQexec(dbc->conn, "COMMIT");
	if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
	{
		LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
		PQclear(res);
		return ERROR;
	}
	PQclear(res);

	return OK;
}