void Query::withOuter(QString relationName) { rName = relationName; relation_s r = schema->getRelation(rName); try { if((r.link.first != "") && (r.link.second != "") && (r.type != 0)) { TableSchema *sch = r.model->getSchema(); outerJoin = " LEFT OUTER JOIN "; outerJoin += sch->getTableName() + " ON "; outerJoin += schema->getRelation(rName).link.first; outerJoin += " = " + schema->getRelation(rName).link.second; } else { throw r; } } catch(relation_s) { qDebug() << "[Query::WithOuter]:\tError! Can not get relation" << rName << "!"; qDebug() << r.link.first << "; " << r.link.second << "; " << r.type; } }
static std::vector<TableSchema_Column_ColumnType> BuildColumnVector(const TableSchema &table_schema) { std::vector<TableSchema_Column_ColumnType> result{}; result.reserve(table_schema.columns_size()); for (auto column : table_schema.columns()) { result.emplace_back(column.type()); } return result; }
QVariant modelData( const QModelIndex & idx, int role ) const { if( role == Qt::DisplayRole && mTable ) { switch( idx.column() ) { case 0: return mTable->className(); case 1: return "Table"; case 2: return mTable->tableName(); } } return QVariant(); }
Table * projectReserveTable() { static Table * ret = 0; if( !ret ) { TableSchema * schema = new TableSchema( classesSchema() ); new Field( schema, "fkeyproject", "Project" ); new Field( schema, "arsenalSlotReserve", Field::Double ); new Field( schema, "currentAllocation", Field::Double ); ret = schema->table(); } return ret; }
void MainWindow::expandChildTables( const QModelIndex & idx ) { for( ModelIter it = idx.isValid() ? ModelIter(idx.child(0,0)) : ModelIter(mModel); it.isValid(); ++it ) { if( TableTranslator::isType(*it) ) { TableSchema * ts = TableTranslator::data(*it).mTable; if( ts->children().size() ) { mUI.mTreeView->expand( *it ); expandChildTables( *it ); } } } }
TableSchema * TableDialog::createTable( QWidget * parent, Schema * schema, TableSchema * parTable ) { TableSchema * table = new TableSchema( schema ); if( parTable ) table->setParent( parTable ); TableDialog * td = new TableDialog( table, parent ); td->setWindowTitle( "Create Table" ); if( td->exec() == QDialog::Accepted ) { td->applySettings(); } else { delete table; table = 0; } delete td; return table; }
virtual void loadChildren( const QModelIndex & parentIndex, SuperModel * model ) { if( TableTranslator::isType(parentIndex) ) { TableSchema * table = TableTranslator::data(parentIndex).mTable; // Add child tables mTableTranslator->appendList( table->children(), parentIndex ); // Add fields inside a fields group QModelIndex fieldGroup = mStandardTranslator->append( parentIndex ); model->setData( fieldGroup, "Fields", Qt::DisplayRole ); mFieldTranslator->appendList( table->ownedFields(), fieldGroup ); // Add Indexes inside an index group QModelIndex indexGroup = mStandardTranslator->append( parentIndex ); model->setData( indexGroup, "Indexes", Qt::DisplayRole ); mIndexTranslator->appendList( table->indexes(), indexGroup ); } }
QString Record::displayName() const { Table * t = table(); if( t ) { TableSchema * ts = t->schema(); Field * field = 0; foreach( Field * f, ts->fields() ) if( f->flag( Field::DisplayName ) ) { field = f; break; } if( !field ) field = ts->field("name",true); if( !field ) field = ts->field("displayname",true); if( !field ) field = ts->field(ts->className(),true); if( !field ) field = ts->field(ts->tableName(),true); if( field ) return getValue( field->pos() ).toString(); } return QString(); }
PyObject * sipWrapRecord( Record * r, bool makeCopy, TableSchema * defaultType ) { PyObject * ret = 0; // First we convert to Record using sip methods static sipTypeDef * recordType = getRecordType( "blur.Stone", "Record" ); sipTypeDef * type = recordType; if( type ) { if( makeCopy ) ret = getSipAPI()->api_convert_from_new_type( new Record(*r), type, NULL ); else { ret = getSipAPI()->api_convert_from_type( r, type, Py_None ); } } else { LOG_1( "Stone.Record not found" ); return 0; } Table * table = r->table(); TableSchema * tableSchema = 0; if( table ) tableSchema = table->schema(); else if( defaultType ) tableSchema = defaultType; else return ret; bool isErr = false; if( tableSchema ) { QString className = tableSchema->className(); // Then we try to find the python class for the particular schema class type // from the desired module set using addSchemaCastModule // BORROWED ref PyObject * dict = getSchemaCastModule( tableSchema->schema() ); if( dict ) { SIP_BLOCK_THREADS // BORROWED ref PyObject * klass = PyDict_GetItemString( dict, className.toLatin1().constData() ); if( klass ) { PyObject * tuple = PyTuple_New(1); // Tuple now holds only ref to ret PyTuple_SET_ITEM( tuple, 0, ret ); PyObject * result = PyObject_CallObject( klass, tuple ); if( result ) { if( PyObject_IsInstance( result, klass ) == 1 ) { ret = result; } else { LOG_1( "Cast Ctor Result is not a subclass of " + className ); Py_INCREF( ret ); Py_DECREF( result ); } } else { LOG_1( "runPythonFunction: Execution Failed, Error Was:\n" ); PyErr_Print(); isErr = true; } Py_DECREF( tuple ); } SIP_UNBLOCK_THREADS if( isErr ) return 0; } else LOG_1( "No cast module set for schema" ); } else LOG_1( "Table has no schema" );