コード例 #1
0
ファイル: main.c プロジェクト: c-aries/utt-part
void
add_content (struct utt_cache *cache)
{
  gint page = 2;

  utt_cache_add (cache, "utt-wubi/page", &page, sizeof (page));
  utt_cache_add (cache, "utt/main", &page, sizeof (page));
  utt_cache_add (cache, "utt-wubi/info", &page, sizeof (page));
  page = 3;
  utt_cache_update (cache, "utt-wubi/page", &page, sizeof (page));
  query_content (cache);
}
コード例 #2
0
ファイル: main.c プロジェクト: c-aries/utt-part
int
main (int argc, char *argv[])
{
  struct utt_cache *cache;

  cache = utt_cache_new ();
  utt_cache_set_cachefile (cache, "cache-file");
  /* add_content (cache); */
  query_content (cache);
  /* utt_cache_flush (cache); */
  utt_cache_destroy (cache);
  return 0;
}
コード例 #3
0
ファイル: SpiceInfo.cpp プロジェクト: ray-zong/spice
QVector<SpiceByContent> SpiceInfo::queryContent(const QString &name)
{
    QVector<SpiceByContent> vecSpice;

    QSqlDatabase db;
    if(!createConnection(db))
    {
        return vecSpice;
    }

    QSqlQuery query(db);
    //content
    query.prepare("SELECT id, englishName, chineseName FROM content "
                  "WHERE chineseName like :chineseName OR englishName like :englishName");
    query.bindValue(":chineseName", "%" + name + "%");
    query.bindValue(":englishName", "%" + name + "%");
    if(!query.exec())
    {
        qDebug() << __FILE__ << __LINE__ << query.lastError().text();
    }
    SpiceByContent content;
    while(query.next())
    {
        int contentId = query.value(0).toInt();
        QSqlQuery query_content(db);
        query_content.prepare("SELECT spiceId, relativeValue, absoluteValue FROM spice_content "
                              "WHERE contentId=:id");
        query_content.bindValue(":id", contentId);
        if(query_content.exec())
        {
            while(query_content.next())
            {
                content.id = query_content.value(0).toInt();
                content.relativeContent = query_content.value(1).toDouble();
                content.absoluteContent = query_content.value(2).toDouble();

                QSqlQuery query_information(db);
                query_information.prepare("SELECT englishName, chineseName FROM spice_information "
                                          "WHERE id=:id");
                query_information.bindValue(":id", content.id);
                if(query_information.exec())
                {
                    if(query_information.next())
                    {
                        content.name.EnList = query_information.value(0).toString().split(';');
                        content.name.CnList = query_information.value(1).toString().split(';');

                        vecSpice.push_back(content);
                    }
                }
                else
                {
                    qDebug() << __FILE__ << __LINE__ << query_information.lastError().text();
                }
            }
        }
        else
        {
            qDebug() << __FILE__ << __LINE__ << query_content.lastError().text();
        }
    }
    // 连接使用完后需要释放回数据库连接池
    ConnectionPool::closeConnection(db);
    return vecSpice;
}
コード例 #4
0
ファイル: SpiceInfo.cpp プロジェクト: ray-zong/spice
QVector<SpiceInfoData> SpiceInfo::querySpice(const QString &name)
{
    QVector<SpiceInfoData> vecSpiceInfo;

    QSqlDatabase db;
    if(!createConnection(db))
    {
        // 连接使用完后需要释放回数据库连接池
        ConnectionPool::closeConnection(db);
        return vecSpiceInfo;
    }

    QSqlQuery query(db);
    //spice_information
    query.prepare("SELECT id, englishName, chineseName, typeId, property, sense, extract, origin, purpose, imagePath, FEMA, FDA, COE, GB, density, refractive, solubility FROM spice_information "
                  "WHERE chineseName like :chineseName OR englishName like :englishName");
    query.bindValue(":chineseName", "%" + name + "%");
    query.bindValue(":englishName", "%" + name + "%");
    if(!query.exec())
    {
        qDebug() << __FILE__ << __LINE__ << query.lastError().text();
    }

    while(query.next())
    {

        SpiceInfoData spiceInfo;
        spiceInfo.id = query.value(0).toInt();
        spiceInfo.name.EnList = query.value(1).toString().split(';');
        spiceInfo.name.CnList = query.value(2).toString().split(';');
        spiceInfo.type = query.value(3).toInt();
        spiceInfo.property = query.value(4).toString();
        spiceInfo.sense = query.value(5).toString();
        spiceInfo.extract = query.value(6).toString();
        spiceInfo.origin = query.value(7).toString();
        spiceInfo.purpose = query.value(8).toString();
        spiceInfo.imagePath = query.value(9).toString();
        spiceInfo.management.FEMA = query.value(10).toString();
        spiceInfo.management.FDA = query.value(11).toString();
        spiceInfo.management.COE = query.value(12).toString();
        spiceInfo.management.GB = query.value(13).toString();
        spiceInfo.physics.density = query.value(14).toString();
        spiceInfo.physics.refractive = query.value(15).toString();
        spiceInfo.physics.solubility = query.value(16).toString();

        //spice_content
        QSqlQuery query_content(db);
        query_content.prepare("SELECT retentionTime, absoluteValue, relativeValue, contentId FROM spice_content "
                              "WHERE spiceId=:id");
        query_content.bindValue(":id", spiceInfo.id);
        if(!query_content.exec())
        {
            qDebug() << __FILE__ << __LINE__ << query_content.lastError().text();
        }

        SpiceContent content;
        while(query_content.next())
        {
            content.retentionTime = query_content.value(0).toDouble();
            content.absoluteContent = query_content.value(1).toDouble();
            content.relativeContent = query_content.value(2).toDouble();
            int contentId = query_content.value(3).toInt();
            QSqlQuery query_1(db);
            query_1.prepare("SELECT chineseName, englishName FROM content WHERE id=:id");
            query_1.bindValue(":id",contentId);
            if(query_1.exec())
            {
                if(query_1.next())
                {
                    content.chineseName = query_1.value(0).toString();
                    content.englishName = query_1.value(1).toString();

                    spiceInfo.vecContent.push_back(content);
                }
            }
            else
            {
                qDebug() << __FILE__ << __LINE__ << query_1.lastError().text();
            }
        }
        vecSpiceInfo.push_back(spiceInfo);
    }
    // 连接使用完后需要释放回数据库连接池
    ConnectionPool::closeConnection(db);

    return vecSpiceInfo;
}
コード例 #5
0
ファイル: SpiceInfo.cpp プロジェクト: ray-zong/spice
bool SpiceInfo::findSpice(int id, SpiceInfoData &spiceInfo)
{
    QSqlDatabase db;
    if(!createConnection(db))
    {
        return false;
    }

    QSqlQuery query(db);
    //spice_information
    query.prepare("SELECT englishName, chineseName, typeId, property, sense, extract, origin, purpose, imagePath, FEMA, FDA, COE, GB, density, refractive, solubility FROM spice_information WHERE id=:id");
    query.bindValue(":id", id);
    if(!query.exec())
    {
        qDebug() << __FILE__ << __LINE__ << query.lastError().text();
    }

    if(query.next())
    {
        spiceInfo.id = id;
        spiceInfo.name.EnList = query.value(0).toString().split(';');
        spiceInfo.name.CnList = query.value(1).toString().split(';');
        spiceInfo.type = query.value(2).toInt();
        spiceInfo.property = query.value(3).toString();
        spiceInfo.sense = query.value(4).toString();
        spiceInfo.extract = query.value(5).toString();
        spiceInfo.origin = query.value(6).toString();
        spiceInfo.purpose = query.value(7).toString();
        spiceInfo.imagePath = query.value(8).toString();
        spiceInfo.management.FEMA = query.value(9).toString();
        spiceInfo.management.FDA = query.value(10).toString();
        spiceInfo.management.COE = query.value(11).toString();
        spiceInfo.management.GB = query.value(12).toString();
        spiceInfo.physics.density = query.value(13).toString();
        spiceInfo.physics.refractive = query.value(14).toString();
        spiceInfo.physics.solubility = query.value(15).toString();

        //spice_content
        query.prepare("SELECT retentionTime, absoluteValue, relativeValue, contentId FROM spice_content WHERE spiceId=:id");
        query.bindValue(":id", id);
        if(!query.exec())
        {
            qDebug() << __FILE__ << __LINE__ << query.lastError().text();
        }

        SpiceContent content;
        while(query.next())
        {
            content.retentionTime = query.value(0).toDouble();
            content.absoluteContent = query.value(1).toDouble();
            content.relativeContent = query.value(2).toDouble();
            int contentId = query.value(3).toInt();
            QSqlQuery query_content(db);
            query_content.prepare("SELECT chineseName, englishName FROM content WHERE id=:id");
            query_content.bindValue(":id", contentId);
            if(!query_content.exec())
            {
                qDebug() << __FILE__ << __LINE__ << query.lastError().text();
            }

            if(!query_content.next())
            {
                Q_ASSERT(false);
                continue;
            }
            content.chineseName = query_content.value(0).toString();
            content.englishName = query_content.value(1).toString();

            spiceInfo.vecContent.push_back(content);
        }
    }

    // 连接使用完后需要释放回数据库连接池
    ConnectionPool::closeConnection(db);

    return true;
}