Ir para conteúdo

Featured Replies

Postado

Erro quando vou compilar meu servidor:

 

 

#include "otpch.h"
#include <iostream>

#include "database.h"
#include "databasepgsql.h"

#include "configmanager.h"
extern ConfigManager g_config;

DatabasePgSQL::DatabasePgSQL()
{
    std::stringstream dns;
    dns << "host='" << g_config.getString(ConfigManager::SQL_HOST) << "' dbname='" << g_config.getString(ConfigManager::SQL_DB) << "' user='" << g_config.getString(ConfigManager::SQL_USER) << "' password='" << g_config.getString(ConfigManager::SQL_PASS) << "' port='" << g_config.getNumber(ConfigManager::SQL_PORT) << "'";

    m_handle = PQconnectdb(dns.str().c_str());
    m_connected = PQstatus(m_handle) == CONNECTION_OK;
    if(!m_connected)
        std::clog << "Failed to estabilish PostgreSQL database connection: " << PQerrorMessage(m_handle) << std::endl;
}

bool DatabasePgSQL::getParam(DBParam_t param)
{
    switch(param)
    {
        case DBPARAM_MULTIINSERT:
            return true;

        default:
            break;
    }

    return false;
}

bool DatabasePgSQL::query(const std::string& query)
{
    if(!m_connected)
        return false;

    // executes query
    PGresult* res = PQexec(m_handle, _parse(query).c_str());
    ExecStatusType stat = PQresultStatus(res);
    if(stat != PGRES_COMMAND_OK && stat != PGRES_TUPLES_OK)
    {
        std::clog << "PQexec(): " << query << ": " << PQresultErrorMessage(res) << std::endl;
        PQclear(res);
        return false;
    }

    // everything went fine
    PQclear(res);
    return true;
}

DBResult* DatabasePgSQL::storeQuery(const std::string& query)
{
    if(!m_connected)
        return NULL;

    // executes query
    PGresult* res = PQexec(m_handle, _parse(query).c_str());
    ExecStatusType stat = PQresultStatus(res);
    if(stat != PGRES_COMMAND_OK && stat != PGRES_TUPLES_OK)
    {
        std::clog << "PQexec(): " << query << ": " << PQresultErrorMessage(res) << std::endl;
        PQclear(res);
        return false;
    }

    // everything went fine
    DBResult* result = new PgSQLResult(res);
    return verifyResult(result);
}

std::string DatabasePgSQL::escapeString(const std::string& s)
{
    // remember to quote even empty string!
    if(!s.size())
        return std::string("''");

    // the worst case is 2n + 1
    int32_t error;
    char* output = new char[(s.length() * 2) + 1];
    // quotes escaped string and frees temporary buffer
    PQescapeStringConn(m_handle, output, s.c_str(), s.length(), reinterpret_cast<int32_t*>(&error));

    std::string r = std::string("'");
    r += output;
    r += "'";

    delete[] output;
    return r;
}

std::string DatabasePgSQL::escapeBlob(const char *s, uint32_t length)
{
    // remember to quote even empty stream!
    if(!s)
        return std::string("''");

    // quotes escaped string and frees temporary buffer
    size_t len;
    char* output = (char*)PQescapeByteaConn(m_handle, (uint8_t*)s, length, &len);

    std::string r = std::string("E'");
    r += output;
    r += "'";

    PQfreemem(output);
    return r;
}

uint64_t DatabasePgSQL::getLastInsertId()
{
    if(!m_connected)
        return 0;

    PGresult* res = PQexec(m_handle, "SELECT LASTVAL() as last;");
    ExecStatusType stat = PQresultStatus(res);
    if(stat != PGRES_COMMAND_OK && stat != PGRES_TUPLES_OK)
    {
        std::clog << "PQexec(): \"SELECT LASTVAL() as last\": " << PQresultErrorMessage(res) << std::endl;
        PQclear(res);
        return 0;
    }

    const uint64_t id = atoll(PQgetvalue(res, 0, PQfnumber(res, "last")));
    PQclear(res);
    return id;
}

std::string DatabasePgSQL::_parse(const std::string& s)
{
    std::string query = "";
    bool inString = false;
    for(uint32_t a = 0; a < s.length(); a++)
    {
        uint8_t ch = s[a];
        if(ch == '\'')
        {
            if(inString && s[a + 1] != '\'')
                inString = false;
            else
                inString = true;
        }

        if(ch == '`' && !inString)
            ch = '"';

        query += ch;
    }

    return query;
}

const char* PgSQLResult::getDataStream(const std::string& s, uint64_t& size)
{
    std::string buf = PQgetvalue(m_handle, m_cursor, PQfnumber(m_handle, s.c_str()));
    uint8_t* temp = PQunescapeBytea( (const uint8_t*)buf.c_str(), (size_t*)&size);

    char* value = new char[buf.size()];
    strcpy(value, (char*)temp);

    PQfreemem(temp);
    return value;
}

void PgSQLResult::free()
{
    if(!m_handle)
    {
        std::clog << "[Critical - PgSQLResult::free] Trying to free already freed result!!!" << std::endl;
        return;
    }

    PQclear(m_handle);
    m_handle = NULL;
    delete this;
}

bool PgSQLResult::next()
{
    if(m_cursor >= m_rows)
        return false;

    m_cursor++;
    return true;
}

PgSQLResult::~PgSQLResult()
{
    if(m_handle)
        PQclear(m_handle);
}

PgSQLResult::PgSQLResult(PGresult* result)
{
    if(!result)
        return;

    m_handle = result;
    m_cursor = -1;
    m_rows = PQntuples(m_handle) - 1;
}
 

  • 1 month later...
  • Respostas 187
  • Visualizações 93.4k
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

  • Natanael Beckman
    Natanael Beckman

    Obrigado Luan, galera não custa nada, clica em gostei ou comentar agradecendo, um ato pequeno pra você e é o nosso combustível pra continuar postando bons tutoriais.

  • luanluciano93
    luanluciano93

    Muito bom cara, vai ajudar muita gente, continue assim, reputado!

  • eu compilo todos os TFS que peguei com dev c++ e funciona pelo menos aki em casa '-'   ta faltando as openssl no seu dev c++ tente usa essas openssl

Posted Images

Postado

 C:\Users\PR0-Desktop\ot\Source\dev-cpp\Makefile.win [Build Error]  [obj//actions.o] Error 1 

ajuda por favor

 

error nao compilo

  • 1 month later...
Postado
  Em 30/11/2015 em 21:28, rogylennon disse:

Fiz tudo da maneira como você falou, baixei o de 64 bits, meu computador é de 64, e surgiu o seguinte erro

 

Sem títuloerrrrrrrrrrrrrrrrrroooooooooooooooooooooooooooooooo.png

conseguiu reSOLVER este erro ?

  • 1 month later...
Postado
  Em 22/07/2014 em 04:44, iErrorzz disse:

Mano baixei o seu Trunk

Ai fis os procedimentos peguei a data/lib , data/npc/lib e items

Ai botei tudo isso no Data do Trunk ai fui tentar conpilar e deu esse erro

Ajuda ae

 

iRirhJU.png

eu tava com esse problema mais resolvi esse utilizando o Dev C++ do topico.

Editado por jeffersonxvr
resolvi o problema (veja o histórico de edições)

  • 2 weeks later...

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo