当前位置: 首页>>代码示例>>C++>>正文


C++ DatabaseConnectionPtr::getEncoding方法代码示例

本文整理汇总了C++中DatabaseConnectionPtr::getEncoding方法的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseConnectionPtr::getEncoding方法的具体用法?C++ DatabaseConnectionPtr::getEncoding怎么用?C++ DatabaseConnectionPtr::getEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatabaseConnectionPtr的用法示例。


在下文中一共展示了DatabaseConnectionPtr::getEncoding方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: query

IceGrid::ApplicationInfo 
SqlStringApplicationInfoDict::find(const DatabaseConnectionPtr& connection,
                                   const string& name)
{
    QSqlQuery query(connection->sqlConnection());
    string queryString = "SELECT * FROM ";
    queryString += _table;
    queryString += " WHERE name = ?;";

    query.prepare(queryString.c_str());
    query.bindValue(0, name.c_str());

    if(!query.exec())
    {
        throwDatabaseException(__FILE__, __LINE__, query.lastError());
    }

    if(query.next())
    {
        IceGrid::ApplicationInfo info;
        info.uuid = query.value(1).toString().toUtf8().data();
        info.createTime = query.value(2).toLongLong();
        info.createUser = query.value(3).toString().toUtf8().data();
        info.updateTime = query.value(4).toLongLong();
        info.updateUser = query.value(5).toString().toUtf8().data();
        info.revision = query.value(6).toInt();

        QByteArray bytes = query.value(7).toByteArray();

        IceInternal::InstancePtr instance = IceInternal::getInstance(_communicator);
        IceInternal::BasicStream stream(instance.get(), connection->getEncoding());
        stream.b.resize(bytes.size());
        ::memcpy(&stream.b[0], bytes.data(), bytes.size());
        stream.i = stream.b.begin();
        stream.startReadEncaps();
        stream.read(info.descriptor);
        stream.readPendingObjects();
        stream.endReadEncaps();

        return info;
    }
    else
    {
       throw NotFoundException(__FILE__, __LINE__);
    }
}
开发者ID:2008hatake,项目名称:zeroc-ice,代码行数:46,代码来源:SqlStringApplicationInfoDict.cpp

示例2: stream

void 
SqlStringApplicationInfoDict::put(const DatabaseConnectionPtr& connection,
                                  const string& name,
                                  const ApplicationInfo& info)
{
    IceInternal::InstancePtr instance = IceInternal::getInstance(_communicator);
    IceInternal::BasicStream stream(instance.get(), connection->getEncoding());
    stream.startWriteEncaps();
    stream.write(info.descriptor);
    stream.writePendingObjects();
    stream.endWriteEncaps();

    QSqlQuery query(connection->sqlConnection());
    ostringstream queryString;
    queryString << "UPDATE " << _table << " SET uuid = ?, createTime = '" << info.createTime 
                << "', createUser = ?, updateTime = '" << info.updateTime << "', updateUser = ?, revision = '" 
                << info.revision << "', descriptor = ";

    QString driver = connection->sqlConnection().driverName();
    if(driver == "QPSQL" || driver == "QODBC")
    {
        vector<Ice::Byte> bytes(stream.b.size());
        ::memcpy(&bytes[0], stream.b.begin(), stream.b.size());

        if(driver == "QPSQL")
        {
            queryString << "E'" << escapePsqlBinary(bytes) << "'";
        }
        else
        {
            queryString << "0x" << escapeOdbcBinary(bytes);
        }
    }
    else
    {
        queryString << "?";
    }
    queryString << " WHERE name = ?;";

    query.prepare(queryString.str().c_str());

    int placeholder = 0;
    query.bindValue(placeholder++, info.uuid.c_str());
    query.bindValue(placeholder++, info.createUser.c_str());
    query.bindValue(placeholder++, info.updateUser.c_str());

    if(driver != "QPSQL" && driver != "QODBC")
    {
        QByteArray bytes;
        bytes.resize(static_cast<int>(stream.b.size()));
        ::memcpy(bytes.data(), stream.b.begin(), stream.b.size());
        QVariant descriptor(bytes);

        query.bindValue(placeholder++, descriptor);
    }
    query.bindValue(placeholder, name.c_str());

    if(!query.exec())
    {
        throwDatabaseException(__FILE__, __LINE__, query.lastError());
    }

    if(query.numRowsAffected() == 0)
    {
        //
        // We do a find since some databases (MySQL) return 0 for number of rows affected
        // if row exists but data was not changed from previous values.
        //
        try
        {
            find(connection, name);
        }
        catch(const NotFoundException&)
        {
            QSqlQuery insertQuery(connection->sqlConnection());
            queryString.str("");
            queryString << "INSERT INTO " << _table << " VALUES(?, ?, '" << info.createTime << "', ?, '"
                        << info.updateTime << "', ?, '" << info.revision << "', ";

            if(driver == "QPSQL" || driver == "QODBC")
            {
                vector<Ice::Byte> bytes(stream.b.size());
                ::memcpy(&bytes[0], stream.b.begin(), stream.b.size());
 
                if(driver == "QPSQL")
                {
                    queryString << "E'" << escapePsqlBinary(bytes) << "'";
                }
                else
                {
                    queryString << "0x" << escapeOdbcBinary(bytes);
                }
            }
            else
            {
                queryString << "?";
            }
            queryString << ");";
 
            insertQuery.prepare(queryString.str().c_str());
//.........这里部分代码省略.........
开发者ID:2008hatake,项目名称:zeroc-ice,代码行数:101,代码来源:SqlStringApplicationInfoDict.cpp


注:本文中的DatabaseConnectionPtr::getEncoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。