PyObject *DBRowToRow(DBResultRow &row, const char *type) { PyDict *args = new PyDict(); PyObject *res = new PyObject( type, args ); //list off the column names: uint32 cc = row.ColumnCount(); PyList *header = new PyList(cc); args->SetItemString("header", header); for(uint32 r = 0; r < cc; r++) { header->SetItemString(r, row.ColumnName(r)); } //lines: PyList *rowlist = new PyList(cc); args->SetItemString("line", rowlist); //add a line entry for the row: for(uint32 r = 0; r < cc; r++) { rowlist->SetItem(r, DBColumnToPyRep(row, r)); } return res; }
PyTuple *DBResultToTupleSet(DBQueryResult &result) { uint32 cc = result.ColumnCount(); if(cc == 0) return new PyTuple(0); uint32 r; PyTuple *res = new PyTuple(2); PyList *cols = new PyList(cc); PyList *reslist = new PyList(); res->items[0] = cols; res->items[1] = reslist; //list off the column names: for(r = 0; r < cc; r++) { cols->SetItemString(r, result.ColumnName(r)); } //add a line entry for each result row: DBResultRow row; while(result.GetRow(row)) { PyList *linedata = new PyList(cc); reslist->items.push_back(linedata); for(r = 0; r < cc; r++) { linedata->SetItem(r, DBColumnToPyRep(row, r)); } } return res; }
PyDict* CRowSet::_CreateKeywords(DBRowDescriptor* rowDesc) { assert( rowDesc ); PyDict* keywords = new PyDict; keywords->SetItemString( "header", rowDesc ); uint32 cc = rowDesc->ColumnCount(); PyList* columns = new PyList( cc ); for( uint32 i = 0; i < cc; i++ ) columns->SetItem( i, new PyString( *rowDesc->GetColumnName( i ) ) ); keywords->SetItemString( "columns", columns ); return keywords; }
PyList *DBResultToPackedRowList( DBQueryResult &result ) { DBRowDescriptor *header = new DBRowDescriptor( result ); PyList *res = new PyList( result.GetRowCount() ); DBResultRow row; for( uint32 i = 0; result.GetRow( row ); i++ ) { res->SetItem( i, CreatePackedRow( row, header ) ); PyIncRef( header ); } PyDecRef( header ); return res; }
PyObject *DBResultToIndexRowset(DBQueryResult &result, uint32 key_index) { uint32 cc = result.ColumnCount(); //start building the IndexRowset PyDict *args = new PyDict(); PyObject *res = new PyObject( new PyString( "util.IndexRowset" ), args ); if(cc == 0 || cc < key_index) return res; //list off the column names: PyList *header = new PyList(cc); args->SetItemString("header", header); for(uint32 i = 0; i < cc; i++) header->SetItemString(i, result.ColumnName(i)); //RowClass: args->SetItemString("RowClass", new PyToken("util.Row")); //idName: args->SetItemString("idName", new PyString( result.ColumnName(key_index) )); //items: PyDict *items = new PyDict(); args->SetItemString("items", items); //add a line entry for each result row: DBResultRow row; while(result.GetRow(row)) { PyRep *key = DBColumnToPyRep(row, key_index); PyList *line = new PyList(cc); for(uint32 i = 0; i < cc; i++) line->SetItem(i, DBColumnToPyRep(row, i)); items->SetItem(key, line); } return res; }
PyObject *DBResultToRowset(DBQueryResult &result) { uint32 r; uint32 cc = result.ColumnCount(); PyDict *args = new PyDict(); PyObject *res = new PyObject( new PyString( "util.Rowset" ), args ); /* check if we have a empty query result and return a empty RowSet */ if( cc == 0 ) return res; //list off the column names: PyList *header = new PyList( cc ); args->SetItemString("header", header); for(r = 0; r < cc; r++) { header->SetItemString( r, result.ColumnName(r)); } //RowClass: args->SetItemString("RowClass", new PyToken("util.Row")); //lines: PyList *rowlist = new PyList(); args->SetItemString("lines", rowlist); //add a line entry for each result row: DBResultRow row; while(result.GetRow(row)) { PyList *linedata = new PyList( cc ); rowlist->AddItem(linedata); for(r = 0; r < cc; r++) { linedata->SetItem( r, DBColumnToPyRep(row, r) ); } } return res; }
/* function not used */ PyTuple *DBResultToPackedRowListTuple( DBQueryResult &result ) { DBRowDescriptor * header = new DBRowDescriptor( result ); size_t row_count = result.GetRowCount(); PyList * list = new PyList( row_count ); DBResultRow row; uint32 i = 0; while( result.GetRow(row) ) { list->SetItem( i++, CreatePackedRow( row, header ) ); PyIncRef( header ); } PyTuple * root = new PyTuple(2); root->SetItem( 0, header ); root->SetItem( 1, list ); return root; }