Example #1
0
bool CWizIndexBase::createUserEx(const WIZBIZUSER& data)
{
    qDebug() << "create user, alias: " << data.alias;

    Q_ASSERT(!data.bizGUID.isEmpty() && !data.userGUID.isEmpty());

    CString strFormat = FormatInsertSQLFormat(TABLE_NAME_WIZ_USER,
                                              FIELD_LIST_WIZ_USER,
                                              PARAM_LIST_WIZ_USER);

    CString strSQL;
    strSQL.Format(strFormat,
                  STR2SQL(data.bizGUID).utf16(),
                  STR2SQL(data.userId).utf16(),
                  STR2SQL(data.userGUID).utf16(),
                  STR2SQL(data.alias).utf16(),
                  STR2SQL(data.pinyin).utf16()
        );


    if (!ExecSQL(strSQL))
        return false;

    if (!m_bUpdating) {
        emit userCreated(data);
    }

    return true;
}
Example #2
0
bool CWizIndexBase::CreateTagEx(const WIZTAGDATA& d)
{
    qDebug() << "create tag, name: " << d.strName;

    Q_ASSERT(d.strKbGUID == m_strKbGUID);

    WIZTAGDATA data = d;
    if (data.strGUID == data.strParentGUID) {
        data.strParentGUID.clear();
    }

    CString strFormat = FormatInsertSQLFormat(TABLE_NAME_WIZ_TAG, FIELD_LIST_WIZ_TAG, PARAM_LIST_WIZ_TAG);

    CString strSQL;
    strSQL.Format(strFormat,
        STR2SQL(data.strGUID).utf16(),
        STR2SQL(data.strParentGUID).utf16(),
        STR2SQL(data.strName).utf16(),
        STR2SQL(data.strDescription).utf16(),
        TIME2SQL(data.tModified).utf16(),
        WizInt64ToStr(data.nVersion).utf16()
        );


    if (!ExecSQL(strSQL))
        return false;

    if (!m_bUpdating) {
        emit tagCreated(data);
    }

    return true;
}
Example #3
0
bool CWizIndexBase::TagFromGUID(const CString& strTagGUID, WIZTAGDATA& data)
{
    if (!strTagGUID || !*strTagGUID) {
        TOLOG(_T("TagGUID is empty"));
        return false;
    }

    CString strWhere;
    strWhere.Format(_T("TAG_GUID=%s"),
        STR2SQL(strTagGUID).utf16()
        );

    CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_TAG, FIELD_LIST_WIZ_TAG, strWhere);

    CWizTagDataArray arrayTag;
    if (!SQLToTagDataArray(strSQL, arrayTag)) {
        TOLOG(_T("Failed to get tag by guid"));
        return false;
    }

    if (arrayTag.empty()) {
        //TOLOG(_T("Failed to get tag by guid, result is empty"));
        return false;
    }

    data = arrayTag[0];
    return true;
}
Example #4
0
bool CWizIndexBase::AttachmentFromGUID(const CString& strAttachcmentGUID,
                                       WIZDOCUMENTATTACHMENTDATA& data)
{
    if (strAttachcmentGUID.IsEmpty()) {
        TOLOG(_T("AttahcmentGUID is empty"));
        return false;
    }

    CString strWhere;
    strWhere.Format(_T("ATTACHMENT_GUID=%s"),
        STR2SQL(strAttachcmentGUID).utf16()
        );

    CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_DOCUMENT_ATTACHMENT, FIELD_LIST_WIZ_DOCUMENT_ATTACHMENT, strWhere);

    CWizDocumentAttachmentDataArray arrayDocumentAttachment;
    if (!SQLToDocumentAttachmentDataArray(strSQL, arrayDocumentAttachment)) {
        TOLOG(_T("Failed to get attachment attachment by guid"));
        return false;
    }

    if (arrayDocumentAttachment.empty()) {
        //TOLOG(_T("Failed to get attachment by guid, result is empty"));
        return false;
    }

    data = arrayDocumentAttachment[0];
    return true;
}
Example #5
0
bool CWizIndexBase::StyleFromGUID(const CString& strStyleGUID, WIZSTYLEDATA& data)
{
    if (!strStyleGUID || !*strStyleGUID) {
        TOLOG(_T("StyleGUID is empty"));
        return false;
    }

    CString strWhere;
    strWhere.Format(_T("STYLE_GUID=%s"),
        STR2SQL(strStyleGUID).utf16()
        );

    CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_STYLE, FIELD_LIST_WIZ_STYLE, strWhere);

    CWizStyleDataArray arrayStyle;
    if (!SQLToStyleDataArray(strSQL, arrayStyle)) {
        TOLOG(_T("Failed to get style by guid"));
        return false;
    }

    if (arrayStyle.empty()) {
        //TOLOG(_T("Failed to get style by guid, result is empty"));
        return false;
    }

    data = arrayStyle[0];
    return true;
}
Example #6
0
bool CThumbIndex::AbstractIsExist(const CString& guid, const CString& type)
{
    if(!m_dbThumb.IsOpened())
        return false;
    CString sql = CString("select ") + "ABSTRACT_GUID" + " from " +TABLE_NAME_ABSTRACT+" where ABSTRACT_GUID='"
    +guid+ ("' AND ABSTRACT_TYPE=")
    +STR2SQL(type)
    +(";");
    try {
        CppSQLite3Query query = m_dbThumb.execQuery(sql);
        while (!query.eof()) {
            return true;
        }
		return false;
	}
	catch (const CppSQLite3Exception& e)
	{
		TOLOG(e.errorMessage());
        TOLOG(sql);
		return false;
	}
	catch (...) {
		TOLOG("Unknown exception while close DB");
		return false;
	}
}
Example #7
0
bool CWizIndexBase::ModifyTagEx(const WIZTAGDATA& d)
{
    qDebug() << "modify tag, name: " << d.strName;

    Q_ASSERT(d.strKbGUID == m_strKbGUID);

    WIZTAGDATA dataOld;
    TagFromGUID(d.strGUID, dataOld);

    WIZTAGDATA data = d;
    if (data.strGUID == data.strParentGUID) {
        data.strParentGUID.Empty();
    }

    CString strFormat = FormatUpdateSQLFormat(TABLE_NAME_WIZ_TAG, FIELD_LIST_WIZ_TAG_MODIFY, TABLE_KEY_WIZ_TAG);

    CString strSQL;
    strSQL.Format(strFormat,
        STR2SQL(data.strParentGUID).utf16(),
        STR2SQL(data.strName).utf16(),
        STR2SQL(data.strDescription).utf16(),
        TIME2SQL(data.tModified).utf16(),
        WizInt64ToStr(data.nVersion).utf16(),
        STR2SQL(data.strGUID).utf16()
        );

    if (!ExecSQL(strSQL))
        return false;

    WIZTAGDATA dataNew;
    TagFromGUID(d.strGUID, dataNew);

    if (!m_bUpdating) {
        emit tagModified(dataOld, dataNew);
    }

    return true;
}
Example #8
0
bool CWizIndexBase::userFromGUID(const QString& bizGUID,
                                 const QString& userGUID,
                                 WIZBIZUSER& user)
{
    CString strWhere = "BIZ_GUID=%1 AND USER_GUID=%2";
    strWhere = strWhere.arg(STR2SQL(bizGUID)).arg(STR2SQL(userGUID));

    CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_USER,
                                    FIELD_LIST_WIZ_USER,
                                    strWhere);

    CWizBizUserDataArray arrayUser;
    if (!SQLToBizUserDataArray(strSQL, arrayUser)) {
        TOLOG("[userFromGUID] failed to get user by user guid");
        return false;
    }

    if (arrayUser.empty())
        return false;

    user = arrayUser[0];
    return true;
}
Example #9
0
bool CWizIndexBase::modifyUserEx(const WIZBIZUSER& user)
{
    qDebug() << "modify user, alias: " << user.alias;

    Q_ASSERT(!user.bizGUID.isEmpty() && !user.userGUID.isEmpty());

    // save old user info
    WIZBIZUSER userOld;
    userFromGUID(user.bizGUID, user.userGUID, userOld);

    CString strWhere = "BIZ_GUID=%s AND USER_GUID=%s";
    strWhere = strWhere.arg(STR2SQL(user.bizGUID)).arg(STR2SQL(user.userGUID));

    CString strFormat = FormatUpdateSQLByWhere(TABLE_NAME_WIZ_USER,
                                              FIELD_LIST_WIZ_USER_MODIFY,
                                              strWhere);

    CString strSQL;
    strSQL.Format(strFormat,
                  STR2SQL(user.alias).utf16(),
                  STR2SQL(user.pinyin).utf16()
        );

    if (!ExecSQL(strSQL))
        return false;

    // read new user info
    WIZBIZUSER userNew;
    userFromGUID(user.bizGUID, user.userGUID, userNew);

    if (!m_bUpdating) {
        emit userModified(userOld, userNew);
    }

    return true;
}
Example #10
0
bool CWizIndexBase::ModifyStyleEx(const WIZSTYLEDATA& data)
{
    qDebug() << "modify style, name: " << data.strName;

    Q_ASSERT(data.strKbGUID == m_strKbGUID);

    WIZSTYLEDATA dataOld;
    StyleFromGUID(data.strGUID, dataOld);

    CString strFormat = FormatUpdateSQLFormat(TABLE_NAME_WIZ_STYLE, FIELD_LIST_WIZ_STYLE_MODIFY, TABLE_KEY_WIZ_STYLE);

    CString strSQL;
    strSQL.Format(strFormat,
        STR2SQL(data.strName).utf16(),
        STR2SQL(data.strDescription).utf16(),
        COLOR2SQL(data.crTextColor).utf16(),
        COLOR2SQL(data.crBackColor).utf16(),
        data.bTextBold ? 1 : 0,
        data.nFlagIndex,
        TIME2SQL(data.tModified).utf16(),
        WizInt64ToStr(data.nVersion).utf16(),
        STR2SQL(data.strGUID).utf16()
        );

    if (!ExecSQL(strSQL))
        return false;

    WIZSTYLEDATA dataNew;
    StyleFromGUID(data.strGUID, dataNew);

    if (!m_bUpdating) {
        emit styleModified(dataOld, dataNew);
    }

    return true;
}
Example #11
0
bool CWizIndexBase::GetAllDocumentsSize(int& count, bool bIncludeTrash /* = false */)
{
    CString strSQL;
    if (bIncludeTrash) {
        strSQL = FormatQuerySQL(TABLE_NAME_WIZ_DOCUMENT, "COUNT(*)");
    } else {
        CString strWhere;
        strWhere.Format("DOCUMENT_LOCATION not like %s",
                        STR2SQL(QString(LOCATION_DELETED_ITEMS) + _T("%")).utf16());

        strSQL = FormatQuerySQL(TABLE_NAME_WIZ_DOCUMENT, "COUNT(*)", strWhere);
    }

    return SQLToSize(strSQL, count);
}
Example #12
0
bool CWizIndexBase::userFromGUID(const QString& strUserGUID,
                                 CWizBizUserDataArray& arrayUser)
{
    CString strWhere;
    strWhere.Format("USER_GUID=%s", STR2SQL(strUserGUID).utf16());

    CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_USER,
                                    FIELD_LIST_WIZ_USER,
                                    strWhere);

    if (!SQLToBizUserDataArray(strSQL, arrayUser)) {
        TOLOG("[userFromGUID] failed to get user by user guid");
        return false;
    }

    if (arrayUser.empty())
        return false;

    return true;
}
Example #13
0
bool CWizIndexBase::DeleteStyleEx(const WIZSTYLEDATA& data)
{
    qDebug() << "delete style, name: " << data.strName;

    Q_ASSERT(data.strKbGUID == m_strKbGUID);

    CString strFormat = FormatDeleteSQLFormat(TABLE_NAME_WIZ_STYLE, TABLE_KEY_WIZ_STYLE);

    CString strSQL;
    strSQL.Format(strFormat,
        STR2SQL(data.strGUID).utf16()
        );

    if (!ExecSQL(strSQL))
        return false;

    if (!m_bUpdating) {
        emit styleDeleted(data);
    }

    return true;
}
Example #14
0
bool CWizIndexBase::DeleteDocumentEx(const WIZDOCUMENTDATA& data)
{
    qDebug() << "delete document, title: " << data.strTitle;

    Q_ASSERT(data.strKbGUID == m_strKbGUID);

    CString strFormat = FormatDeleteSQLFormat(TABLE_NAME_WIZ_DOCUMENT, TABLE_KEY_WIZ_DOCUMENT);

    CString strSQL;
    strSQL.Format(strFormat,
        STR2SQL(data.strGUID).utf16()
        );

    if (!ExecSQL(strSQL))
        return false;

    if (!m_bUpdating) {
        emit documentDeleted(data);
    }

    return true;
}
Example #15
0
bool CWizIndexBase::messageFromDocumentGUID(const QString& strGUID, WIZMESSAGEDATA& data)
{
    CString strWhere;
    strWhere.Format("DOCUMENT_GUID=%s", STR2SQL(strGUID).utf16());

    CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_MESSAGE,
                                    FIELD_LIST_WIZ_MESSAGE,
                                    strWhere);

    CWizMessageDataArray arrayMessage;
    if (!SQLToMessageDataArray(strSQL, arrayMessage)) {
        TOLOG("[messageFromId] failed to get message by document guid");
        return false;
    }

    if (arrayMessage.empty())
        return false;

    // FIXME: return the lastest message
    data = arrayMessage[0];
    return true;
}
bool CThumbIndex::AbstractFromGUID(const CString& guid, WIZABSTRACT &abstract,const CString& type)
{
    if(!m_dbThumb.IsOpened())
        return false;

    CString sql = CString("select ") + FIELD_LIST_ABSTRACT + " from " + TABLE_NAME_ABSTRACT +" where ABSTRACT_GUID='"
                    + guid + ("' AND ABSTRACT_TYPE=")
                    + STR2SQL(type)
                    + (";");
    try
    {
        CppSQLite3Query query = m_dbThumb.execQuery(sql);

        while (!query.eof())
        {
            abstract.guid = query.getStringField(0);
            abstract.text = query.getStringField(2);
            int length;
            const unsigned char * imageData = query.getBlobField(3, length);
            if (imageData && length)
            {
                abstract.image.loadFromData(imageData, length);
            }
            return true;
        }
		return false;
	}
	catch (const CppSQLite3Exception& e)
	{
		TOLOG(e.errorMessage());
        TOLOG(sql);
		return false;
	}
	catch (...) {
		TOLOG("Unknown exception while close DB");
		return false;
	}
}
Example #17
0
bool CWizIndexBase::DeleteAttachmentEx(const WIZDOCUMENTATTACHMENTDATA& data)
{
    qDebug() << "delete attachment, name: " << data.strName;

    Q_ASSERT(data.strKbGUID == m_strKbGUID);

    CString strFormat = FormatDeleteSQLFormat(TABLE_NAME_WIZ_DOCUMENT_ATTACHMENT,
                                              "ATTACHMENT_GUID");

    CString strSQL;
    strSQL.Format(strFormat,
        STR2SQL(data.strGUID).utf16()
        );

    if (!ExecSQL(strSQL))
        return false;

    if (!m_bUpdating) {
        emit attachmentDeleted(data);
    }

    return true;
}
Example #18
0
bool CWizIndexBase::CreateAttachmentEx(const WIZDOCUMENTATTACHMENTDATA& data)
{
    qDebug() << "create attachment, name: " << data.strName;

    Q_ASSERT(data.strKbGUID == m_strKbGUID);

    //CString strInfoMD5 = CalDocumentAttachmentInfoMD5(data);
    //if (strInfoMD5 != data.strInfoMD5) {
    //    TOLOG2(_T("Warning: Attachment info md5 does not match: %1, %2"), strInfoMD5, data.strInfoMD5);
    //}

    CString strFormat = FormatInsertSQLFormat(TABLE_NAME_WIZ_DOCUMENT_ATTACHMENT, FIELD_LIST_WIZ_DOCUMENT_ATTACHMENT, PARAM_LIST_WIZ_DOCUMENT_ATTACHMENT);

    CString strSQL;
    strSQL.Format(strFormat,
        STR2SQL(data.strGUID).utf16(),
        STR2SQL(data.strDocumentGUID).utf16(),
        STR2SQL(data.strName).utf16(),
        STR2SQL(data.strURL).utf16(),
        STR2SQL(data.strDescription).utf16(),
        TIME2SQL(data.tInfoModified).utf16(),
        STR2SQL(data.strInfoMD5).utf16(),
        TIME2SQL(data.tDataModified).utf16(),
        STR2SQL(data.strDataMD5).utf16(),
        WizInt64ToStr(data.nVersion).utf16()
    );

    if (!ExecSQL(strSQL))
        return false;

    if (!m_bUpdating) {
        emit attachmentCreated(data);
    }

    return true;
}
Example #19
0
bool CWizIndexBase::ModifyAttachmentInfoEx(const WIZDOCUMENTATTACHMENTDATA& data)
{
    qDebug() << "modify attachment, name: " << data.strName;

    Q_ASSERT(data.strKbGUID == m_strKbGUID);

    WIZDOCUMENTATTACHMENTDATA dataOld;
    AttachmentFromGUID(data.strGUID, dataOld);

    CString strFormat = FormatUpdateSQLFormat(TABLE_NAME_WIZ_DOCUMENT_ATTACHMENT, FIELD_LIST_WIZ_DOCUMENT_ATTACHMENT_MODIFY, TABLE_KEY_WIZ_DOCUMENT_ATTACHMENT);

    CString strSQL;
    strSQL.Format(strFormat,
        STR2SQL(data.strName).utf16(),
        STR2SQL(data.strURL).utf16(),
        STR2SQL(data.strDescription).utf16(),
        TIME2SQL(data.tInfoModified).utf16(),
        STR2SQL(data.strInfoMD5 ).utf16(),
        TIME2SQL(data.tDataModified).utf16(),
        STR2SQL(data.strDataMD5 ).utf16(),
        WizInt64ToStr(data.nVersion).utf16(),
        STR2SQL(data.strGUID).utf16()
    );

    if (!ExecSQL(strSQL))
        return false;

    WIZDOCUMENTATTACHMENTDATA dataNew;
    AttachmentFromGUID(data.strGUID, dataNew);

    if (!m_bUpdating) {
        emit attachmentModified(dataOld, dataNew);
    }

    return true;
}
Example #20
0
bool CThumbIndex::UpdateAbstract(const WIZABSTRACT &abstractNew, const CString& type)
{
    if(!m_dbThumb.IsOpened())
    {
        TOLOG(_T("Fault error: thumb database does not opened"));
        return false;
    }
    //
    QByteArray data;
    if (abstractNew.image.width() > 0 && abstractNew.image.height() > 0)
    {
        int width = abstractNew.image.width();
        int height = abstractNew.image.height();
        //
        QImage img;
        if (width > 120
            || height > 120)
        {
            img = abstractNew.image.scaled(120, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation);
        }
        else
        {
            img = abstractNew.image;
        }
        //
        if (img.isNull())
        {
            TOLOG(_T("Faile to scale image to abstract"));
            return false;
        }
        //
        QBuffer buffer(&data);
        buffer.open(QIODevice::WriteOnly);
        if (!img.save(&buffer, "JPG"))
        {
            TOLOG(_T("Faile to save abstract image data to buffer"));
            return false;
        }
        buffer.close();
    }
    //
    //
    WIZABSTRACT abstractOld;
    if (AbstractFromGUID(abstractNew.guid ,abstractOld, type))
    {
        CString whereFiled = CString("ABSTRACT_GUID=")
                                + STR2SQL(abstractNew.guid)
                                +(" AND ABSTRACT_TYPE = ")
                                +STR2SQL(type);

        // sqlite use '' instead of '
        CString absText = CString(abstractNew.text);
        absText = absText.replace("'","");

        CString sql = CString("update ") + \
                TABLE_NAME_ABSTRACT + \
                " set ABSTRACT_TEXT" + "='" + \
                absText + "' where " + whereFiled;
        try
        {
            m_dbThumb.execDML(sql);
            m_dbThumb.updateBlob(TABLE_NAME_ABSTRACT, "ABSTRACT_IMAGE", (const unsigned char*)data.constData() , data.length(), whereFiled);
            return true;
        }
        catch (const CppSQLite3Exception& e)
        {
            TOLOG(e.errorMessage());
            TOLOG(sql);
            return false;
        }
        catch (...)
        {
            TOLOG("Unknown exception while update document");
            return false;
        }
    }
    else
    {
        CString sql = CString("insert into ") + TABLE_NAME_ABSTRACT + ("(") + FIELD_LIST_ABSTRACT + (")")
            + " values("
        + STR2SQL(abstractNew.guid) + (",")
        + STR2SQL(type) + (",")
        + STR2SQL(abstractNew.text) + (",?)");
        try
        {
            m_dbThumb.insertBlob(sql, (const unsigned char*)data.constData() , data.length());
            return true;
        }
        catch (const CppSQLite3Exception& e)
        {
            TOLOG(e.errorMessage());
            TOLOG(sql);
            return false;
        }
        catch (...)
        {
            TOLOG("Unknown exception while update document");
            return false;
        }
    }
    
	//
	return true;
    
}
Example #21
0
bool CWizIndexBase::ModifyDocumentInfoEx(const WIZDOCUMENTDATA& dataCur)
{
    qDebug() << "modify document, title: " << dataCur.strTitle;

    Q_ASSERT(dataCur.strKbGUID == m_strKbGUID);

    WIZDOCUMENTDATA dataOld;
    DocumentFromGUID(dataCur.strGUID, dataOld);

    WIZDOCUMENTDATA data = dataCur;

    // try to fill the fields not allowed empty
    if (data.strTitle.isEmpty()) {
        if (!dataOld.strTitle.isEmpty()) {
            data.strTitle = dataOld.strTitle;
        } else {
            data.strTitle = "New note";
        }

        TOLOG2("Document Title is empty: %1, Try to rename to the %2", data.strGUID, data.strTitle);
    }

    if (data.strLocation.isEmpty()) {
        if (!dataOld.strLocation.isEmpty()) {
            data.strLocation = dataOld.strLocation;
        } else {
            data.strLocation = "/My Notes/";
        }

        TOLOG2("Document Location is empty: %1, Try to relocation to the %2", data.strTitle, data.strLocation);
    }

    CString strFormat = FormatUpdateSQLFormat(TABLE_NAME_WIZ_DOCUMENT, FIELD_LIST_WIZ_DOCUMENT_MODIFY, TABLE_KEY_WIZ_DOCUMENT);

    CString strSQL;
    strSQL.Format(strFormat,
        STR2SQL(data.strTitle).utf16(),
        STR2SQL(data.strLocation).utf16(),
        STR2SQL(data.strName).utf16(),
        STR2SQL(data.strSEO).utf16(),
        STR2SQL(data.strURL).utf16(),
        STR2SQL(data.strAuthor).utf16(),
        STR2SQL(data.strKeywords).utf16(),
        STR2SQL(data.strType).utf16(),
        STR2SQL(data.strOwner).utf16(),
        STR2SQL(data.strFileType).utf16(),
        STR2SQL(data.strStyleGUID).utf16(),

        TIME2SQL(data.tCreated).utf16(),
        TIME2SQL(data.tModified).utf16(),
        TIME2SQL(data.tAccessed).utf16(),

        data.nIconIndex,
        data.nSync,
        data.nProtected,
        data.nReadCount,
        data.nAttachmentCount,
        data.nIndexed,

        TIME2SQL(data.tInfoModified).utf16(),
        STR2SQL(data.strInfoMD5 ).utf16(),
        TIME2SQL(data.tDataModified).utf16(),
        STR2SQL(data.strDataMD5 ).utf16(),
        TIME2SQL(data.tParamModified).utf16(),
        STR2SQL(data.strParamMD5 ).utf16(),
        WizInt64ToStr(data.nVersion).utf16(),

        STR2SQL(data.strGUID).utf16()
    );

    if (!ExecSQL(strSQL))
        return false;

    WIZDOCUMENTDATA dataNew;
    DocumentFromGUID(data.strGUID, dataNew);

    if (!m_bUpdating) {
        emit documentModified(dataOld, dataNew);
    }

    return true;
}
Example #22
0
bool CWizIndexBase::CreateDocumentEx(const WIZDOCUMENTDATA& dataNew)
{
    qDebug() << "create document, title: " << dataNew.strTitle;

    Q_ASSERT(dataNew.strKbGUID == m_strKbGUID);

    WIZDOCUMENTDATA data = dataNew;

    // try to fill the fields not allowed empty
    if (data.strTitle.isEmpty()) {
        TOLOG1("Document Title is empty: %1, Try to rename to the \"New note\"", data.strGUID);
        data.strTitle = "New note";
    }

    if (data.strLocation.isEmpty()) {
        TOLOG1("Document Location is empty: %1, Try to relocation to the /My Notes/", data.strTitle);
        data.strLocation = "/My Notes/";
    }

    CString strFormat = FormatInsertSQLFormat(TABLE_NAME_WIZ_DOCUMENT, FIELD_LIST_WIZ_DOCUMENT, PARAM_LIST_WIZ_DOCUMENT);

    CString strSQL;
    strSQL.Format(strFormat,
        STR2SQL(data.strGUID).utf16(),
        STR2SQL(data.strTitle).utf16(),
        STR2SQL(data.strLocation).utf16(),
        STR2SQL(data.strName).utf16(),
        STR2SQL(data.strSEO).utf16(),
        STR2SQL(data.strURL).utf16(),
        STR2SQL(data.strAuthor).utf16(),
        STR2SQL(data.strKeywords).utf16(),
        STR2SQL(data.strType).utf16(),
        STR2SQL(data.strOwner).utf16(),
        STR2SQL(data.strFileType).utf16(),
        STR2SQL(data.strStyleGUID).utf16(),

        TIME2SQL(data.tCreated).utf16(),
        TIME2SQL(data.tModified).utf16(),
        TIME2SQL(data.tAccessed).utf16(),

        data.nIconIndex,
        data.nSync,
        data.nProtected,
        data.nReadCount,
        data.nAttachmentCount,
        data.nIndexed,

        TIME2SQL(data.tInfoModified).utf16(),
        STR2SQL(data.strInfoMD5).utf16(),
        TIME2SQL(data.tDataModified).utf16(),
        STR2SQL(data.strDataMD5).utf16(),
        TIME2SQL(data.tParamModified).utf16(),
        STR2SQL(data.strParamMD5).utf16(),
        WizInt64ToStr(data.nVersion).utf16()
    );

    if (!ExecSQL(strSQL))
        return false;

    if (!m_bUpdating) {
        emit documentCreated(data);
    }

    return true;
}
Example #23
0
bool CWizIndexBase::createMessageEx(const WIZMESSAGEDATA& data)
{
    qDebug() << "create message, id: " << data.nId;

    CString strFormat = FormatInsertSQLFormat(TABLE_NAME_WIZ_MESSAGE,
                                              FIELD_LIST_WIZ_MESSAGE,
                                              PARAM_LIST_WIZ_MESSAGE);

    CString strSQL;
    strSQL.Format(strFormat,
                  WizInt64ToStr(data.nId).utf16(),
                  STR2SQL(data.bizGUID).utf16(),
                  STR2SQL(data.kbGUID).utf16(),
                  STR2SQL(data.documentGUID).utf16(),
                  STR2SQL(data.senderAlias).utf16(),
                  STR2SQL(data.senderId).utf16(),
                  STR2SQL(data.senderGUID).utf16(),
                  STR2SQL(data.receiverAlias).utf16(),
                  STR2SQL(data.receiverId).utf16(),
                  STR2SQL(data.receiverGUID).utf16(),
                  data.nMessageType,
                  data.nReadStatus,
                  TIME2SQL(data.tCreated).utf16(),
                  STR2SQL(data.title).utf16(),
                  STR2SQL(data.messageBody).utf16(),
                  WizInt64ToStr(data.nVersion).utf16()
        );


    if (!ExecSQL(strSQL))
        return false;

    if (!m_bUpdating) {
        emit messageCreated(data);
    }

    return true;
}
Example #24
0
bool CThumbIndex::UpdateAbstract(const WIZABSTRACT &abstractNew, const CString& type)
{
    if(!m_dbThumb.IsOpened()) {
        TOLOG(_T("Fault error: thumb database does not opened"));
        return false;
    }

    QByteArray data;
    if (abstractNew.image.width() > 0 && abstractNew.image.height() > 0)
    {
        int width = abstractNew.image.width();
        int height = abstractNew.image.height();

        // process thumbnail
        QImage img;
        if (width >= 120 && height >= 120) {
            if (width > height) {
                img = abstractNew.image.scaledToHeight(120, Qt::SmoothTransformation);
                img = img.copy((img.width() - 120)/2, 0, 120, 120);
            } else {
                img = abstractNew.image.scaledToWidth(120, Qt::SmoothTransformation);
                img = img.copy(0, (img.height() - 120)/2, 120, 120);
            }
        } else if (width > 120 || height > 120) {
            img = abstractNew.image.scaled(120, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation);
        } else {
            img = abstractNew.image;
        }

        if (img.isNull())
        {
            TOLOG(_T("Faile to scale image to abstract"));
            return false;
        }
        //
        QBuffer buffer(&data);
        buffer.open(QIODevice::WriteOnly);
        if (!img.save(&buffer, "JPG"))
        {
            TOLOG(_T("Faile to save abstract image data to buffer"));
            return false;
        }
        buffer.close();
    }


    WIZABSTRACT abstractOld;
    if (AbstractFromGUID(abstractNew.guid ,abstractOld, type))
    {
        CString whereField = CString("ABSTRACT_GUID=%1 and ABSTRACT_TYPE=%2")
                             .arg(STR2SQL(abstractNew.guid))
                             .arg(STR2SQL(type));

        CString strSql = CString("update %1 set ABSTRACT_TEXT=%2 where %3")
                         .arg(TABLE_NAME_ABSTRACT)
                         .arg(STR2SQL(abstractNew.text))
                         .arg(whereField);

        try
        {
            m_dbThumb.execDML(strSql);
            m_dbThumb.updateBlob(TABLE_NAME_ABSTRACT, "ABSTRACT_IMAGE", (const unsigned char*)data.constData() , data.length(), whereField);
            return true;
        }
        catch (const CppSQLite3Exception& e)
        {
            TOLOG(e.errorMessage());
            TOLOG(strSql);
            return false;
        }
        catch (...)
        {
            TOLOG("Unknown exception while update document");
            return false;
        }
    }
    else
    {
        CString strSql = CString("insert into %1 (%2) values(%3, %4, %5, ?)")
                         .arg(TABLE_NAME_ABSTRACT)
                         .arg(FIELD_LIST_ABSTRACT)
                         .arg(STR2SQL(abstractNew.guid))
                         .arg(STR2SQL(type))
                         .arg(STR2SQL(abstractNew.text));

        try
        {
            m_dbThumb.insertBlob(strSql, (const unsigned char*)data.constData() , data.length());
            return true;
        }
        catch (const CppSQLite3Exception& e)
        {
            TOLOG(e.errorMessage());
            TOLOG(strSql);
            return false;
        }
        catch (...)
        {
            TOLOG("Unknown exception while update document");
            return false;
        }
    }

    return true;
}