dbID ArchiveMan::archiveDocumentDb( KraftDoc *doc ) { /* mysql> describe archdoc; +---------------+--------------+------+-----+-------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+--------------+------+-----+-------------------+----------------+ | archDocID | int(11) | NO | PRI | NULL | auto_increment | | ident | varchar(32) | YES | MUL | NULL | | | docType | varchar(255) | YES | | NULL | | | clientAddress | text | YES | | NULL | | | clientUid | varchar(32) | YES | | NULL | | | salut | varchar(255) | YES | | NULL | | | goodbye | varchar(128) | YES | | NULL | | | printDate | timestamp | NO | | CURRENT_TIMESTAMP | | | date | date | YES | | NULL | | | pretext | text | YES | | NULL | | | posttext | text | YES | | NULL | | | country | varchar(32) | YES | | NULL | | | language | varchar(32) | YES | | NULL | | | projectLabel | varchar(255) | YES | | NULL | | | state | int(11) | YES | | NULL | | +---------------+--------------+------+-----+-------------------+----------------+ */ if( ! doc ) return dbID(); QSqlTableModel model; model.setTable("archdoc"); QSqlRecord record = model.record(); if( doc->isNew() ) { kDebug() << "Strange: Document in archiving is new!" << endl; } record.setValue( "ident", doc->ident() ); record.setValue( "docType", doc->docType() ); record.setValue( "docDescription", KraftDB::self()->mysqlEuroEncode( doc->whiteboard() ) ); record.setValue( "clientAddress", doc->address() ); record.setValue( "clientUid", doc->addressUid() ); record.setValue( "salut", doc->salut() ); record.setValue( "goodbye", doc->goodbye() ); record.setValue( "printDate", KraftDB::self()->currentTimeStamp() ); record.setValue( "date", doc->date() ); record.setValue( "pretext", KraftDB::self()->mysqlEuroEncode(doc->preText() ) ); record.setValue( "posttext", KraftDB::self()->mysqlEuroEncode(doc->postText() ) ); record.setValue( "projectLabel", KraftDB::self()->mysqlEuroEncode(doc->projectLabel() ) ); record.setValue( "country", doc->country() ); record.setValue( "language", doc->language() ); record.setValue( "tax", DocumentMan::self()->tax( doc->date() ) ); record.setValue( "reducedTax", DocumentMan::self()->reducedTax( doc->date() ) ); if(!model.insertRecord(-1, record)) { kDebug() << model.lastError(); } dbID id = KraftDB::self()->getLastInsertID(); archivePos( id.toInt(), doc ); return id; }
dbID ArchiveMan::archiveDocument( KraftDoc *doc ) { if( ! doc ) return dbID(); dbID archId = archiveDocumentDb( doc ); archiveDocumentXml( doc, archId.toString() ); return archId; }
void DocDigestHtmlView::slotLinkClicked(const QUrl& url) { const QUrlQuery q(url); // Url is like "http://localhost/show_last_print?id=5" const QString idStr = q.queryItemValue(QLatin1String("id")); const QString path = url.path(); if( path.endsWith("show_last_print")) { bool ok; emit( showLastPrint( dbID(idStr.toInt(&ok)) ) ); } }
DocDigest DocumentModel::digest( const QModelIndex& index ) const { DocDigest digest( dbID( data(index.sibling(index.row(), Document_Id ), Qt::DisplayRole).toInt() ), data( index.sibling( index.row(), Document_Type ), Qt::DisplayRole).toString(), data( index.sibling( index.row(), Document_ClientId ), Qt::DisplayRole).toString() ); digest.setDate( data( index.sibling( index.row(), Document_CreationDate ), RawTypes ).toDate() ); digest.setLastModified( data( index.sibling( index.row(), Document_LastModified), RawTypes ).toDateTime() ); const QString clientAdr = data( index.sibling( index.row(), Document_ClientAddress), Qt::DisplayRole).toString(); digest.setClientAddress( clientAdr ); QString ident = data( index.sibling( index.row(), Document_Ident), Qt::DisplayRole ).toString(); digest.setIdent( ident ); digest.setWhiteboard( data( index.sibling( index.row(), Document_Whiteboard), Qt::DisplayRole).toString() ); digest.setProjectLabel( data( index.sibling( index.row(), Document_ProjectLabel), Qt::DisplayRole).toString() ); const QString clientId = data( index.sibling( index.row(), Document_ClientId), Qt::DisplayRole).toString(); digest.setClientId( clientId ); if( mAddresses.contains( clientId )) { digest.setAddressee( mAddresses.value( clientId )); } kDebug() << "Querying archdocs for document ident " << ident; QSqlQuery query("SELECT archDocID, ident, printDate, state FROM archdoc WHERE ident='" + ident +"' ORDER BY printDate DESC" ); query.exec(); while(query.next()) { int archDocID = query.value(0).toInt(); const QString dbIdent = query.value(1).toString(); QDateTime printDateTime = query.value(2).toDateTime(); int state = query.value(3).toInt(); digest.appendArchDocDigest( ArchDocDigest( printDateTime, state, dbIdent, dbID(archDocID) ) ); } return digest; }
dbID KraftDB::getLastInsertID() { if(! ( m_db.isValid()) ) return 0; QSqlQuery query; if( mDatabaseDriver.toLower() == "qmysql" ) { query.prepare("SELECT LAST_INSERT_ID()"); query.exec(); } else if( mDatabaseDriver.toLower() == "qsqlite") { query.prepare( "SELECT last_insert_rowid()"); query.exec(); } else { kDebug() << "############# FATAL ERROR: Unknown database driver " << mDatabaseDriver; } int id = -1; if( query.next() ) { id = query.value(0).toInt(); } else { kDebug() << "############# FATAL ERROR: Query for last insert id is invalid!"; } kDebug() << "Last Insert ID: " << id; return dbID(id); }