/*********************************************************************************** Main function for table creation/altering called from tobrowsertable.cpp It will call either createTable either alterTable ************************************************************************************/ QString toOracleExtract::migrateTable(toExtract &ext, std::list<QString> &source, std::list<QString> &destin) const { #ifdef DEBUG qDebug() << "toOracleExtract::migrateTable source="; for (std::list<QString>::iterator i = source.begin(); i != source.end(); i++) { qDebug() << *i; } qDebug() << "toOracleExtract::migrateTable destin="; for (std::list<QString>::iterator i = destin.begin(); i != destin.end(); i++) { qDebug() << *i; } #endif if (source.empty()) { #ifdef DEBUG qDebug() << "New table has to be created."; #endif return createTable(destin); } else { #ifdef DEBUG qDebug() << "Existing table is to be modified."; #endif return alterTable(source, destin); } } // migrateTable
bool FLManager::alterTable(const QString &n) { #ifndef FL_QUICK_CLIENT QString mtd(db_->managerModules()->contentCached(n + QString::fromLatin1(".mtd"))); if (!db_->dbAux()) return false; QSqlCursor c("flmetadata", true, db_->dbAux()); c.setForwardOnly(true); c.setFilter(QString::fromLatin1("tabla='") + n + QString::fromLatin1("'")); c.select(); if (c.next()) return alterTable(c.value("xml").toString(), mtd); else return false; #else return true; #endif }
int SP_HiveSchemaManager :: ensureSchema( sqlite3 * handle, const char * dbname ) { SP_HiveDBSchema * newDB = findDB( dbname ); if( NULL == newDB ) { SP_NKLog::log( LOG_ERR, "ERROR: invalid dbname %s, cannot find schema", dbname ); return -1; } int ret = 0; for( int i = 0; i < newDB->getTableCount(); i++ ) { SP_HiveTableSchema * newTable = newDB->getTable( i ); int oldCount = SP_HiveTableSchema::getTableColumnCount( handle, newTable->getTableName() ); if( oldCount == 0 ) { SP_NKLog::log( LOG_DEBUG, "DEBUG: create [%s]%s", dbname, newTable->getTableName() ); ret = execWithLog( handle, newTable->getDDL() ); } else if( oldCount > 0 ) { if( oldCount < newTable->getColumnCount() ) { SP_HiveTableSchema oldTable; oldTable.init( handle, newTable->getTableName(), "" ); ret = alterTable( handle, newTable, &oldTable ); } else { // not need action } } else { SP_NKLog::log( LOG_ERR, "ERR: cannot get table column count, [%s]%s", dbname, newTable->getTableName() ); ret = -1; } } return ret; }
void Select() { char s[1000]; gets(s); upper_change(s);///There, we change the string alphabat to upper. //puts(s);///转换检测 SQL *sql=new SQL(s); if (sql->Get(sql->GetSize()-1) != ";") {cout<<"plz use ; to the end."<<endl; return ;} if (sql->Get(0) == "exit"){cout<<"ByeBye~"<<endl; exit(0);} if (!sql->Judge()) return ; if (sql->Get(0) == "create" && sql->Get(1) == "table") createTable(sql);//create table s (num int ,name char(10)) else if(sql->Get(0) == "insert" && sql->Get(1) == "into" && sql->Get(3) == "values") insertRecord(sql);//insert into s values () else if (sql->Get(0) == "show") showTable(sql->Get(1)); //show s else if (sql->Get(0) == "drop" && sql->Get(1) == "table") dropTable (sql->Get(2));//drop table s else if (sql->Get(0) =="alter" && sql->Get(1) == "table") alterTable (sql);//alter table s (add name type)/(drop name type) else if (sql->Get(0) =="delete" && sql->Get(1) == "from" && sql->Get(3) == "where") deleteRecord(sql);//delete from s while name = name1 else cout << "The code is error!" << endl; }
FLTableMetaData *FLManager::metadata(const QString &n, bool quick) { if (n.isEmpty() || !db_->dbAux()) return 0; FLTableMetaData *ret = 0; QDomDocument doc(n); QDomElement docElem; QString key; QString *dictKey = 0; QString stream = db_->managerModules()->contentCached(n + QString::fromLatin1(".mtd"), &key); bool newTable = false; bool notSysTable = n.left(3) != "sys" && !isSystemTable(n); if (!notSysTable) dictKey = new QString(n); #ifndef FL_QUICK_CLIENT if (!quick) { if (db_->canRegenTables() && notSysTable) { QSqlRecord *buffer = 0; QString key2; delete dictKey; dictKey = dictKeyMetaData_->find(n); if (dictKey) key2 = *dictKey; if (key2.isEmpty()) { QSqlCursor c("flmetadata", true, db_->dbAux()); c.setForwardOnly(true); c.setFilter(QString::fromLatin1("tabla='") + n + QString::fromLatin1("'")); c.select(); if (c.next()) { c.primeDelete(); c.del(); } buffer = c.primeInsert(); buffer->setValue("tabla", n); if (key.isEmpty()) { buffer->setValue("xml", stream); dictKey = new QString(stream); dictKeyMetaData_->replace(n, dictKey); } else { buffer->setValue("xml", key); dictKey = new QString(key); dictKeyMetaData_->replace(n, dictKey); } newTable = true; c.insert(); } else { if (key != key2) { QString s; if (key2.left(255).find("<!DOCTYPE TMD>", 0, true) == -1) AQ_DISKCACHE_FIND(key2, s); else s = key2; bool mustAlter; if (key.isEmpty()) mustAlter = !checkMetaData(s, stream); else mustAlter = (key != key2); if (mustAlter) { if (alterTable(s, stream, key2)) { QSqlCursor c("flmetadata", true, db_->dbAux()); c.setForwardOnly(true); c.setFilter(QString::fromLatin1("tabla='") + n + QString::fromLatin1("'")); c.select(); c.next(); buffer = c.primeUpdate(); if (key.isEmpty()) { buffer->setValue("xml", stream); dictKey = new QString(stream); dictKeyMetaData_->replace(n, dictKey); } else { buffer->setValue("xml", key); dictKey = new QString(key); dictKeyMetaData_->replace(n, dictKey); } c.update(); } } } } } } else { if (key.isEmpty()) dictKey = new QString(n); else dictKey = new QString(key); } #else if (key.isEmpty()) dictKey = new QString(n); else dictKey = new QString(key); #endif //FL_QUICK_CLIENT if (dictKey) { if (cacheMetaData_ && notSysTable) { ret = cacheMetaData_->find(*dictKey); } else if (cacheMetaDataSys_ && !notSysTable) { ret = cacheMetaDataSys_->find(*dictKey); } if (ret) { FLAccessControlLists *acl = aqApp ->acl(); if (acl) acl->process(ret); if (quick) delete dictKey; return ret; } } if (!FLUtil::domDocumentSetContent(doc, stream)) { #ifdef FL_DEBUG qWarning("FLManager : " + QApplication::tr("Error al cargar los metadatos para la tabla %1").arg(n)); #endif if (quick) delete dictKey; #ifdef FL_QUICK_CLIENT else delete dictKey; #endif return 0; } docElem = doc.documentElement(); ret = metadata(&docElem, quick); if (dictKey && (!notSysTable || (!ret->isQuery() && ret->fieldsNamesUnlock().isEmpty()))) { if (cacheMetaData_ && notSysTable) { cacheMetaData_->insert(*dictKey, ret); } else if (cacheMetaDataSys_ && !notSysTable) { cacheMetaDataSys_->insert(*dictKey, ret); } if (quick) delete dictKey; #ifdef FL_QUICK_CLIENT else delete dictKey; #endif } return ret; }