/* open big database !!!! */
/* i use sheme = "mysql://username:pass@host:port/database" */
const QString dbase
= dns.
path().
replace("/",
"");
type = "Q"+dns.scheme().toUpper();
std::cout << "######### type " << qPrintable(type ) << "\n" << std::endl;
if (!drivers.contains(type)) {
std::cout << "######### " << qPrintable(tr("Unable to Load Driver %1").arg(type)) << "\n" << std::endl;
return false;
}
//// .....user port and so .............
/* open QSQLITE on ram */
cachedb.setDatabaseName(":memory:");
if (!cachedb.open()) {
QMessageBox::critical(0, qApp
->tr
("Cannot open local database"),
qApp->tr("Unable to establish a cache database connection.\n\n"
return false;
}
LoadCache();
/* fill memory table to quick load and runn query */
/* update i send to db mysql if needed relaod LoadCache() */
void DB_Manager::LoadCache()
{
query.exec("DROP TABLE IF EXISTS catememo");
query.exec("create table catememo (id INTEGER PRIMARY KEY AUTOINCREMENT,root_id INTEGER,name varchar(110),lft INTEGER,rgt INTEGER,oldid INTEGER,xmlattribute BLOB)");
mod
->setQuery
(QString("SELECT * FROM %1 ").
arg(TABELLA_CATES
),current
());
const int summline = mod->rowCount();
for (int e = 0; e < summline; ++e) {
line_data.clear();
for (int x = 0; x < mod->columnCount(); ++x) {
QString cellTxt
= "'"+G_Quote
(r.
value(x
).
toString())+"'";
line_data.append(cellTxt);
}
QString cainsert
= QString("insert into catememo values (%1)").
arg(line_data.
join(","));
bool mcis = query.exec(cainsert);
}
}
/* open big database !!!! */
/* i use sheme = "mysql://username:pass@host:port/database" */
QUrl dns(sheme,QUrl::TolerantMode);
const QString dbase = dns.path().replace("/","");
QStringList drivers = QSqlDatabase::drivers();
type = "Q"+dns.scheme().toUpper();
std::cout << "######### type " << qPrintable(type ) << "\n" << std::endl;
if (!drivers.contains(type)) {
std::cout << "######### " << qPrintable(tr("Unable to Load Driver %1").arg(type)) << "\n" << std::endl;
return false;
}
//// .....user port and so .............
db = QSqlDatabase::addDatabase(type,QString("master_mysql_%1").arg(trac));
/* open QSQLITE on ram */
cachedb = QSqlDatabase::addDatabase("QSQLITE");
cachedb.setDatabaseName(":memory:");
if (!cachedb.open()) {
QMessageBox::critical(0, qApp->tr("Cannot open local database"),
qApp->tr("Unable to establish a cache database connection.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
return false;
}
LoadCache();
/* fill memory table to quick load and runn query */
/* update i send to db mysql if needed relaod LoadCache() */
void DB_Manager::LoadCache()
{
QSqlQuery query("",cachedb);
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
query.exec("DROP TABLE IF EXISTS catememo");
query.exec("create table catememo (id INTEGER PRIMARY KEY AUTOINCREMENT,root_id INTEGER,name varchar(110),lft INTEGER,rgt INTEGER,oldid INTEGER,xmlattribute BLOB)");
QStringList line_data;
QSqlQueryModel *mod = new QSqlQueryModel();
mod->setQuery(QString("SELECT * FROM %1 ").arg(TABELLA_CATES),current());
const int summline = mod->rowCount();
for (int e = 0; e < summline; ++e) {
line_data.clear();
QSqlRecord r = mod->record(e);
for (int x = 0; x < mod->columnCount(); ++x) {
QString cellTxt = "'"+G_Quote(r.value(x).toString())+"'";
line_data.append(cellTxt);
}
QString cainsert = QString("insert into catememo values (%1)").arg(line_data.join(","));
bool mcis = query.exec(cainsert);
}
QApplication::restoreOverrideCursor();
}
To copy to clipboard, switch view to plain text mode
Bookmarks