示例#1
0
DBTable *DB::table(const char *tname, int scode, int cols,
		   int access)
     /* throw(PosixError); */
{
  DBTable *ret = 0; /* keep compiler happy */

  switch(access){
  case CREATE:
    if(!isdir(f_name)){
      makedir(f_name);
    }

    ret = new DBTable(this, scode, cols, tname);
    break;

  case READ:
    ret = new DBTable(this, scode, cols, tname);
    ret->file(DB::READ);
    break;

  default:
    abort();
  }

  return ret;
}
示例#2
0
MDatabankPtr WSDatabankTable::operator[](const string& inCode)
{
	if (mDBs.find(inCode) == mDBs.end() or not mDBs[inCode]->IsUpToDate())
	{
		MDatabankPtr db(new MDatabank(inCode));
		db->PrefetchDocWeights("__ALL_TEXT__");
		mDBs[inCode] = db;
	}
	
	return mDBs[inCode];
}
示例#3
0
//------------------------------------------------------------
static void
writeTOC(BookCaseDB &db,
	 info_lib *mmdb,
	 const char *bcname,
	 const char *thisBook,
	 DBCursor &toc_cursor )
{
  DBTable *out = db.DB::table(DATABASE_STDIO,
			      TOC_CODE, NUM_TOC_FIELDS,
			      DB::CREATE);
  const char *aBook;
  const char *nodeLoc;
  const char *parent;
  int childQty;
  char **children;
  int treeSize;
  
  while(toc_cursor.next(STRING_CODE, &aBook,
			STRING_CODE, &nodeLoc,
			STRING_CODE, &parent,
			SHORT_LIST_CODE, &childQty, STRING_CODE, &children,
			INTEGER_CODE, &treeSize,
			NULL)){
    StringList heap;
    
    if(strcmp(aBook, thisBook) != 0){ /* book id has changed! We're done... */
      toc_cursor.undoNext();
      break;
    }

    for(int i = 0; i < childQty; i++){
      heap.append(to_oid(mmdb, bcname, children[i]));
    }
    
    const char *nodeOID = heap.append(to_oid(mmdb, bcname, nodeLoc));
    const char *parentOID = heap.append(to_oid(mmdb, bcname, parent));
    
#ifdef FISH_DEBUG
    DBUG_PRINT("TOC", ("TOC Entry: O:%s treesize: %d\n", nodeOID, treeSize));
#endif
    
    out->insert(OID_CODE, nodeOID,
		OID_CODE, parentOID,
		INTEGER_CODE, treeSize,
		/* first childQty strings in heap are oids for children */
		OID_LIST_CODE, childQty, heap.array(),
		NULL);
  }

  delete out;
}
示例#4
0
//------------------------------------------------------------
//------------------------------------------------------------
static void
writeSGML(BookCaseDB &db,
	  const char *thisBook,
	  DBCursor &sgml_cursor,
	  hashTable<CC_String,BTCollectable> &hd)
{
  DBTable *out = db.DB::table(DATABASE_STDIO,
			      SGML_CONTENT_CODE, 2,
			      DB::CREATE);

  const char *aBook;
  const char *nodeLoc;
  size_t dataLen;
  const char *data;
  char *bufptr;		// Walk through SGML data stream and update LAST fields
  char *nevermind;	// We don't care about the return value from the parse

  while(sgml_cursor.next(STRING_CODE, &aBook,
		    STRING_CODE, &nodeLoc,
		    -STRING_CODE, &data, &dataLen,
		    NULL)){

    if(strcmp(aBook, thisBook) != 0){ /* book id has changed! We're done... */
      sgml_cursor.undoNext();
      break;
    }

#ifdef FISH_DEBUG
    DBUG_PRINT("SGML", ("SGML data for: ::%s `%.40s...' \n",
			nodeLoc, data));
#endif

    FlexBuffer new_node_buffer;
    
    bufptr = (char *) data;
    nevermind = parse4last( bufptr );

    insert_remotelink( &hd, (char *)data, dataLen, &new_node_buffer);
    
    out->insert_untagged(STRING_CODE, nodeLoc,
			 -STRING_CODE,
			 new_node_buffer.GetBuffer(),
			 new_node_buffer.GetSize(),
			 NULL);
  }

  delete out;
}
示例#5
0
文件: StyleTaskDB.C 项目: juddy/edcde
void StyleTaskDB::done(const char * name,
		  const char * online, int online_len,
		  const char * print, int print_len)
{
  /*
   * Use -STRING_CODE instead of STRING_CODE to handle 8-bit clean
   * data
   */
  
  DBTable *tbl = f_bookcase->table(BookCaseDB::StyleSheet);
  
  tbl->insert(STRING_CODE, name,
	      -STRING_CODE, online, (size_t)online_len,
	      -STRING_CODE, print,  (size_t)print_len,
	      NULL);

  reset();
}
示例#6
0
bool BigThread(int iParentID, int iThreadID)
{
   int iNumMessages = 0, iMessageID = -1, iLength = 0;
   double dTick = gettick();
   char szSQL[200];
   DBTable *pMessages = NULL;
   Message *pMessage = NULL;
   list<Message *> pList;
   
   // printf("BigThread entry %d %d\n", iParentID, iThreadID);
   
   pMessages = new DBTable();
   pMessages->BindColumnInt();
   pMessages->BindColumnInt();
   
   sprintf(szSQL, "select messageid,length(message_text) from folder_message_item where parentid=%d", iParentID);
   // printf("BigThread running '%s'\n", szSQL);
   if(pMessages->Execute(szSQL) == false)
   {
      printf("BigThread exit false, query '%s' failed\n", szSQL);
      
      delete pMessages;
	
      return false;
   }
   // printf("BigThread query run (%ld ms)\n", tickdiff(dTick));
   
   while(pMessages->NextRow() == true)
   {
      iNumMessages++;
				
      pMessages->GetField(0, &iMessageID);
      pMessages->GetField(1, &iLength);
      // printf("BigThread %d %d\n", iMessageID, iLength);
      
      pMessage = new Message();
      pMessage->m_iID = iMessageID;
      pMessage->m_iSize = iLength;
      
      pList.push_back(pMessage);
      
      pMessage = MessageGet(iThreadID, false);
      // printf("BigThread %p\n", pMessage);
      pMessage->m_iCount++;
      pMessage->m_iSize += iLength;
   }
   
   delete pMessages;
   
   while(pList.empty() == false)
   {
      pMessage = pList.front();
      BigThread(pMessage->m_iID, iThreadID);
      
      pList.pop_front();
   }
   
   // printf("BigThread exit true, %d messages\n", iNumMessages);
   return true;
}
示例#7
0
//------------------------------------------------------------
static void
writeLCF(BookCaseDB& db, info_lib *mmdb,
	 const char *bcname,
	 hashTable<CC_String,BTCollectable> &hd)
{

  DBTable *out = db.DB::table(DATABASE_STDIO,
			      LOCATOR_CODE, BT_NUM_LOCATOR_FIELDS,
			      DB::CREATE);
  
  hashTableIterator<CC_String,BTCollectable> loc_it( hd );

  while ( ++loc_it ) {
    CC_String *locator_str = ( CC_String *)loc_it.key();
    const char *locator = (const char *)*locator_str;

    BTCollectable *loc_val = ( BTCollectable *)loc_it.value();
    const char *opaque, *nodeloc;
    char* reflabel;
    nodeloc = opaque = (const char *)loc_val->get_value();
    reflabel = strchr(opaque, '\t');
    *reflabel++ = 0;
    
    const char *nodeOID = to_oid(mmdb, bcname, nodeloc);
    
#ifdef FISH_DEBUG
    DBUG_PRINT("LCF", ("LCF entry: L:%s->O:%s\n",
		       locator, nodeOID));
#endif
    out->insert(STRING_CODE, locator,
		OID_CODE, nodeOID,
		STRING_CODE, reflabel,
		NULL);
    
  }

  delete out;
  
}
示例#8
0
int _tmain(int argc, _TCHAR* argv[])
{
	DBInterface* pInterface = new SqliteInterface();
	pInterface->Open("..\\test");

	DBTable table;
	int Col_Content = table.GetColumnIdx("Content");
	if (Col_Content == -1)
	{
		printf("Invalid Column Name\n");
		return false;
	}
	
	pInterface->ExecuteSql("select * from test", table);

// 	for (;;)
// 	{
// 		
// 	}

	printf("I am here, waiting for u\n");
	return 0;
}
示例#9
0
void CMySQLConnection::do_query(DBTable& db_table, const char* sql, int sql_length) throw (CDBException)
{
    MYSQL* mysql_handler = static_cast<MYSQL*>(_mysql_handler);

    // 如果查询成功,返回0。如果出现错误,返回非0值
    if (mysql_real_query(mysql_handler, sql, (unsigned long)sql_length) != 0)
    {
        throw CDBException(NULL, utils::StringFormatter("sql[%s] error: %s", sql, mysql_error(mysql_handler)).c_str(),
                           mysql_errno(mysql_handler), __FILE__, __LINE__);
    }

    // 取结果集
    MYSQL_RES* result_set = mysql_store_result(mysql_handler);
    if (NULL == result_set)
    {
        throw CDBException(sql, utils::StringFormatter("sql[%s] error: %s", sql, mysql_error(mysql_handler)).c_str(),
                           mysql_errno(mysql_handler), __FILE__, __LINE__);
    }
    else
    {
        // 取得字段个数
        int num_fields = mysql_num_fields(result_set);

        while (true)
        {
            MYSQL_ROW row = mysql_fetch_row(result_set);
            if (NULL == row)
            {
                break;
            }

            DBRow db_row;
            for (int i = 0; i < num_fields; ++i)
            {
                const char* field_value = row[i];

                if (NULL == field_value)
                    db_row.push_back(_null_value);
                else
                    db_row.push_back(field_value);
            }

            db_table.push_back(db_row);
        }

        mysql_free_result(result_set);
    }
}
示例#10
0
int main(int argc, char **argv)
{
   int iDebugLevel = 0, iNumMsgs = 0;
   long lMessageID = -1, lParentID = -1, lFolderID = -1, lDate = 0, lFromID = -1, lToID = -1;
   char *szSQL = NULL;
   bytes *pText = NULL, *pSubject = NULL, *pEDF = NULL;
   EDF *pSearch = NULL;
   DBTable *pTable = NULL;
   double dTick = 0;

   if(argc != 3 || !(strcmp(argv[1], "-edf") == 0 || strcmp(argv[1], "-query") == 0))
   {
      printf("Usage: Searching -edf <file>\n");
      printf("Usage: Searching -query <string>\n");

      return 1;
   }

   if(strcmp(argv[1], "-edf") == 0)
   {
      pSearch = EDFParser::FromFile(argv[2]);
      if(pSearch == NULL)
      {
         printf("Could not parse %s, %s\n", argv[2], strerror(errno));
         return 1;
      }

      EDFParser::Print("Search", pSearch);
   }
   else
   {
      pSearch = QueryToEDF(argv[2]);

      printf("Query %s\n", argv[2]);
      EDFParser::Print("Search", pSearch);

      // return 0;
   }
   printf("\n");

   dTick = gettick();
   szSQL = MessageSQL(pSearch);
   printf("SQL(%ld ms): %s\n", tickdiff(dTick), szSQL);
   if(szSQL == NULL)
   {
      printf("Nothing to search for\n");

      return 1;
   }

   if(DBTable::Connect("ua27") == false)
   {
      printf("Cannot connect to database, %s\n", strerror(errno));

      delete pSearch;

      return 1;
   }

   pTable = new DBTable();

   printf("Binding columns\n");

   // messageid
   pTable->BindColumnInt();

   // parentid
   pTable->BindColumnInt();

   // treeid, date, fromid, toid, text
   pTable->BindColumnInt();
   pTable->BindColumnInt();
   pTable->BindColumnInt();
   pTable->BindColumnInt();
   pTable->BindColumnBytes();

   // subject
   pTable->BindColumnBytes();

   // edf
   pTable->BindColumnBytes();

   dTick = gettick();
   printf("Running query\n");
   if(pTable->Execute(szSQL) == true)
   {
      printf("Execute(%ld ms)\n", tickdiff(dTick));

      // iDebugLevel = debuglevel(DEBUGLEVEL_DEBUG);

      dTick = gettick();

      while(pTable->NextRow() == true)
      {
         iNumMsgs++;

         lMessageID = -1;

         lParentID = -1;

         lFolderID = -1;
         lDate = 0;
         lFromID = -1;
         lToID = -1;
         pText = NULL;

         pSubject = NULL;

         pEDF = NULL;

         // messageid
         pTable->GetField(0, &lMessageID);

         // parentid
         pTable->GetField(1, &lParentID);

         // treeid, date, fromid, toid, text
         pTable->GetField(2, &lFolderID);
         pTable->GetField(3, &lDate);
         pTable->GetField(4, &lFromID);
         pTable->GetField(5, &lToID);
         pTable->GetField(6, &pText);

         // subject
         pTable->GetField(7, &pSubject);

         // edf
         pTable->GetField(7, &pEDF);

         printf("m=%ld p=%ld f=%ld d=%ld %ld %ld", lMessageID, lParentID, lFolderID, lDate, lFromID, lToID);
         if(pSubject != NULL)
         {
            printf(", %s", (char *)pSubject->Data(false));
         }
         if(pText != NULL)
         {
            printf(":\n%s", (char *)pText->Data(false));
         }
         printf("\n");

         // delete pEDF;
         // delete pSubject;
         // delete pText;
      }

      // debuglevel(iDebugLevel);

      printf("Found %d messages(%ld ms)\n", iNumMsgs, tickdiff(dTick));
   }
   else
   {
      printf("Query failed, %s\n", strerror(errno));
   }

   delete pTable;

   DBTable::Disconnect();

   delete[] szSQL;

   delete pSearch;

   return 0;
}
示例#11
0
//------------------------------------------------------------
static void
writeCCF(BookCaseDB& db,
	 info_lib *mmdb,
	 const char *bcname )
{

  DBTable *bookMeta = db.table(BookCaseDB::BookMeta, DB::READ);
  DBCursor cursor(*bookMeta);
  DBTable *ccf = db.DB::table(DATABASE_STDIO,
			      DOC_CODE, BT_NUM_DOC_FIELDS,
			      DB::CREATE);

  const char *bookLocator;
  const char *stitle;
  const char *title;
  int seq_no;
  int tabQty;
  const char **tabLines;
  const char *access;

  /*
   * First put the global node table into hash dictionary
   */

  hashTable<CC_String,BTCollectable> global_node_tab(hash_func);
  create_node_dict( global_node_tab , db);  /* throw exception if duplicate
					   node locator is found */
  
  int exception_flag = 0;
  while(cursor.next(STRING_CODE, &bookLocator,
		    STRING_CODE, &stitle,
		    STRING_CODE, &title,
		    INTEGER_CODE, &seq_no,
		    SHORT_LIST_CODE, &tabQty, STRING_CODE, &tabLines,
		    STRING_CODE, &access,
		    NULL)){

    StringList heap;

    /* convert tab to oids in forst tabQty items in heap */
    for(int i = 0; i < tabQty; i++){

      char *t = (char *)tabLines[i];                   

      const char *name = strtok( t, "\t" );
      const char *loc  = strtok( NULL, "\t");
      const char *line = strtok( NULL, "\t");
      const char *file_name = strtok( NULL, "\t");

      int nameLen = strlen( name );

      /*
       * First check if the tab link is resolved
       */

      CC_String key ( loc );
      
      BTCollectable *tab_link = (BTCollectable *)global_node_tab.
	                                            findValue( &key );


      if ( !tab_link ) {
	cerr << "(ERROR)         Tab ID = " << loc << endl
	     << "               of book = " << title << endl
	     << "     specified in file = " << file_name << endl
	     << "               at line = " << line << endl
	     << "     is not pointing to any section ID found in the book\n\n";	
	exception_flag = 1;
      }
      else {
	/*
	 * see if it is a node locator within the same book
	 */
	if ( strcmp( tab_link->get_value(), bookLocator ))  {
	  cerr << "(ERROR)         Tab ID = " << loc << endl
	       << "               of book = " << title << endl
	       << "     specified in file = " << file_name << endl
	       << "               at line = " << line << endl
	       << "     is not pointing to any section ID found in the book\n\n";

	  exception_flag = 1;
	}
      }
	
      // if exception_flag is set, calling to_oid will throw exception
      // It will just loop through all the tabs, and report all the bad ones
      if ( !exception_flag ) {
	const char *tabOID = to_oid(mmdb, bcname, loc);
	char *result = new char[nameLen + 1 + strlen(tabOID) + 1];
	sprintf(result, "%s\t%s", name, tabOID );
	heap.add(result);
      }
    }

    if ( !exception_flag ) {
  
      const char *bookOID = heap.append(to_oid(mmdb, bcname, bookLocator));
      
#ifdef FISH_DEBUG
      DBUG_PRINT("CCF", ("Load Book: O:%s `%s'\n", bookOID, title));
#endif
    
      ccf->insert(OID_CODE, bookOID,
		  STRING_CODE, stitle,
		  STRING_CODE, title,
		  INTEGER_CODE, seq_no,
		  SHORT_LIST_CODE, tabQty, STRING_CODE, heap.array(),
		  STRING_CODE, access,
		  NULL);
    }
  }

  if ( exception_flag ) {
    throw(Unexpected("Tab validation failed"));
  }

  delete ccf;
  global_node_tab.clearAndDestroy();
}
示例#12
0
void WSDatabankTable::ReloadDbs()
{
	mDBs.clear();
	
	cout << endl;
	
	DBInfoVector dbInfo;
	
	if (gConfig != nil and gConfig->GetSetting("/mrs-config/dbs/db", dbInfo))
	{
		for (DBInfoVector::iterator dbi = dbInfo.begin(); dbi != dbInfo.end(); ++dbi)
		{
			if (not dbi->blast)
				continue;
			
			fs::path f = gDataDir / (dbi->name + ".cmp");
				
			cout << "Loading " << dbi->name << " from " << f.string() << " ..."; cout.flush();
				
			try
			{
				MDatabankPtr db(new MDatabank(f.string()));
				db->PrefetchDocWeights("__ALL_TEXT__");
				mDBs[dbi->name] = db;
			}
			catch (exception& e)
			{
				cout << " failed" << endl;
				continue;
			}
			
			cout << " done" << endl;
		}

		string s;
		if (gConfig->GetSetting("/mrs-config/blast-ws/threads", s))
			THREADS = atoi(s.c_str());
	}
	else
	{
		fs::directory_iterator end;
		for (fs::directory_iterator fi(gDataDir); fi != end; ++fi)
		{
			if (is_directory(*fi))
				continue;
			
			string name = fi->leaf();
			
			if (name.length() < 4 or name.substr(name.length() - 4) != ".cmp")
				continue;
			
			name.erase(name.length() - 4);
	
			cout << "Loading " << name << " from " << fi->string() << " ..."; cout.flush();
			
			try
			{
				MDatabankPtr db(new MDatabank(fi->string()));
//				db->PrefetchDocWeights("__ALL_TEXT__");
				mDBs[name] = db;
			}
			catch (exception& e)
			{
				cout << " failed" << endl;
				continue;
			}
			
			cout << " done" << endl;
		}
	}
}
示例#13
0
void TableSetting::setTable(DBTable &table)//доделать атрибуты
{
    idTable = table.getIdTable();
    tableForDeleteAtribute = table;



    item = new QStandardItem(" ");
    model->insertRow(count,item);
    ui->tableViewSitting->setModel(model);
    ui->lineEdit->setText(table.getName());

    QVector<DBAttribute> &attributes = table.getAttributes();

    count = attributes.size();
    delegate();
    qDebug()<<count;

    for(int i=0;i<attributes.size();i++)
    {
        DBAttribute &attribute = attributes[i];

        QStandardItem *itemName = new QStandardItem(attribute.name);
        QStandardItem *itemType = new QStandardItem(attribute.type);
        QStandardItem *itemPK = new QStandardItem(attribute.PK);
        QStandardItem *itemNN = new QStandardItem(attribute.NN);
        QStandardItem *itemU = new QStandardItem(attribute.UNIQ);

        model->setItem(i,0,itemName);
        model->setItem(i,1,itemType);
        if(itemPK->text().toInt()==1)
        {
            model->setData(model->index(i,2,QModelIndex()),2,Qt::CheckStateRole);
        }
        else
        {
            model->setData(model->index(i,2,QModelIndex()),0,Qt::CheckStateRole );
        }
        if(itemNN->text().toInt()==1)
        {
            model->setData(model->index(i,3,QModelIndex()),2,Qt::CheckStateRole);
        }
        else
        {
            model->setData(model->index(i,3,QModelIndex()),0,Qt::CheckStateRole );
        }
        if(itemU->text().toInt()==1)
        {
            model->setData(model->index(i,4,QModelIndex()),2,Qt::CheckStateRole);
        }
        else
        {
            model->setData(model->index(i,4,QModelIndex()),0,Qt::CheckStateRole );
        }
    }

    QVector <DBForeign> &foreigns = table.getForeigns();

    int countConection = foreigns.size();

    if(countConection>0)
    {
        itemConection = new QStandardItem(" ");
        modelConection->insertRow(countConection,itemConection);
    }


    for(int i=0;i<countConection;i++)
    {
        DBTable *table = MainData::getTableById(foreigns[i].foreignTableId);

        modelConection->setItem(i,0,new QStandardItem(table->getName()));

        if(foreigns[i].typeForeign == DBForeign::ONE_TO_ONE)
        {
            modelConection->setItem(i,1,new QStandardItem("1:1"));
        }
        else
        {
            modelConection->setItem(i,1,new QStandardItem("1:N"));
        }
    }

}
示例#14
0
DBTable TableSetting::getTable()//доделать атрибуты
{
    QModelIndex myInName,myInType,myInPK,myInNN,myInU;
    QVariant myDatName,myDatType,myDatPK,myDatNN,myDatU;

    DBTable table;

    table.setIdTable(idTable);

    for(int i = 0;i< model->rowCount();i++)
    {
        myInName=model->index(i,0,QModelIndex());
        myInType=model->index(i,1,QModelIndex());
        myInPK=model->index(i,2,QModelIndex());
        myInNN=model->index(i,3,QModelIndex());
        myInU=model->index(i,4,QModelIndex());

        myDatName=model->data(myInName,Qt::DisplayRole);
        myDatType=model->data(myInType,Qt::DisplayRole);
        myDatPK=model->data(myInPK,Qt::CheckStateRole);
        myDatNN=model->data(myInNN,Qt::CheckStateRole);
        myDatU=model->data(myInU,Qt::CheckStateRole);

        DBAttribute attribute;

        attribute.name = myDatName.toString();
        attribute.type = myDatType.toString();


        if(myDatNN.toInt()==2)
            attribute.NN = "1";
        else
            attribute.NN = "0";

        if(myDatU.toInt()==2)
            attribute.UNIQ = "1";
        else
            attribute.UNIQ = "0";

        if(myDatPK.toInt()==2)
        {
            attribute.PK = "1";
            attribute.NN = "1";
            attribute.UNIQ = "1";
        }
        else
            attribute.PK = "0";

        table.addAttribute(attribute);

    }

    QString tabname = ui->lineEdit->text();
    table.addName(tabname);
    for(int i = 0; i < modelConection->rowCount();i++)
    {
        auto indexTable=modelConection->index(i,0,QModelIndex());
        auto dataTable=modelConection->data(indexTable,Qt::DisplayRole);
        DBTable *ptable = MainData::getTableByName(dataTable.toString());

        indexTable=modelConection->index(i,1,QModelIndex());
        dataTable=modelConection->data(indexTable,Qt::DisplayRole);

        DBForeign::TypeForeign typeForeign = dataTable.toString() == "1:1" ? DBForeign::ONE_TO_ONE : DBForeign::ONE_TO_MANY;

        table.addConnection(DBForeign(ptable->getIdTable(), typeForeign));
    }

    return table;
}
示例#15
0
//------------------------------------------------------------
static void
writeDLP(BookCaseDB &db, info_lib *mmdb,
	 const char *bcname,
	 const char *thisBook,
	 DBCursor &dlp_cursor,
	 hashTable<CC_String,BTCollectable> &node_tab)
{
  DBTable *out = db.DB::table(DATABASE_STDIO,
			      DLP_CODE, 1,
			      DB::CREATE);

  const char *aBook;
  const char *nodeLoc;
  int   line_num;
  const char *toc_file_name;

  hashTable<CC_String, int> link_table(hash_func);
  
  int record_pos = dlp_cursor.tell();
  
  // create the link table  
  while(dlp_cursor.next(STRING_CODE, &aBook,
			STRING_CODE, &nodeLoc,
			INTEGER_CODE, &line_num,
			STRING_CODE,  &toc_file_name,
			NULL)){
    
    if(strcmp(aBook, thisBook) != 0){ /* book id has changed! We're done... */
      dlp_cursor.undoNext();
      break;
    }

    CC_String *key = new CC_String ( nodeLoc );
    link_table.insertKeyAndValue( key, new int(line_num) );
      
#ifdef FISH_DEBUG
    // DBUG_PRINT("DLP", ("DLP Entry: O:%s\n", nodeOID));
#endif
  }

  checkTocLink( toc_file_name, link_table, node_tab ); /* throw exception if
							  unresolved TOC links
							  are found */
  link_table.clearAndDestroy();
  
  dlp_cursor.seekToRec( record_pos );
  out->start_list();
  while ( dlp_cursor.next( STRING_CODE, &aBook,
			   STRING_CODE, &nodeLoc,
			   INTEGER_CODE, &line_num,
			   STRING_CODE, &toc_file_name,
			   NULL)) {

    if(strcmp(aBook, thisBook) != 0){ /* book id has changed! We're done... */
      dlp_cursor.undoNext();
      break;
    }
    const char *nodeOID = to_oid(mmdb, bcname, nodeLoc);
    out->insert_untagged(OID_CODE, nodeOID,
			   NULL);
#ifdef FISH_DEBUG
    DBUG_PRINT("DLP", ("DLP Entry: O:%s\n", nodeOID));
#endif
  }

  out->end_list();

  /* exception thrown in this if failed */
  delete out;
  
}
示例#16
0
bool BigThreads(int iFolderID, int iLimit)
{
   STACKTRACE
   int iNumThreads = 0, iThreadNum = 0, iMessageID = -1, iFromID = -1;
   double dTick = gettick();
   char *szSubject = NULL;
   char szSQL[200];
   DBTable *pThreads = NULL;
   Message *pMessage = NULL, *pThreadList = NULL;
   map<int, Message>::const_iterator pThreadIter;
   
   printf("BigThreads entry %d\n", iFolderID);
   
   pThreads = new DBTable();
   pThreads->BindColumnInt();
   pThreads->BindColumnInt();
   pThreads->BindColumnBytes();

   sprintf(szSQL, "select messageid,fromid,subject from folder_message_item where parentid=-1");
   if(iFolderID != -1)
   {
      sprintf(szSQL, "%s and folderid=%d", szSQL, iFolderID);
   }
   else
   {
      strcat(szSQL, " and folderid <> 384");
   }
   strcat(szSQL, " order by messageid");

   if(pThreads->Execute(szSQL) == false)
   {
      delete pThreads;

      printf("BigThreads exit false, query '%s' failed\n", szSQL);
      return false;
   }
   printf("BigThreads query run (%ld ms)\n", tickdiff(dTick));

   while(pThreads->NextRow() == true)
   {
      if(iNumThreads > 0 && iNumThreads % 100 == 0)
      {
	 printf("BigThreads querying %dth thread\n", iNumThreads);
      }
	   
      iNumThreads++;
      
      pThreads->GetField(0, &iMessageID);
      pThreads->GetField(1, &iFromID);
      pThreads->GetField(2, &szSubject);
      
      // printf("BigThreads query message %d %s\n", iMessageID, szSubject);
      
      pMessage = MessageGet(iMessageID, true);
      pMessage->m_iFromID = iFromID;
      pMessage->m_szSubject = strmk(szSubject);
      
      szSubject = NULL;
   }

   delete pThreads;
   
   printf("BigThreads %d threads\n", iNumThreads);
   
   pThreadList = new Message[iNumThreads];

   pThreadIter = g_pMessages.begin();
   while(pThreadIter != g_pMessages.end())
   {
      if(iThreadNum > 0 && iThreadNum % 100 == 0)
      {
	 printf("BigThreads processing %dth of %d threads\n", iThreadNum, iNumThreads);
      }
      
      pMessage = (Message *)&pThreadIter->second;
      
      BigThread(pMessage->m_iID, pMessage->m_iID);

      pThreadList[iThreadNum] = *pMessage;
      
      pThreadIter++;
      iThreadNum++;
   }
   
   g_iSortType = SORT_COUNT;
   qsort(pThreadList, iNumThreads, sizeof(Message), SortThreads);
   
   if(iLimit == 0 || iLimit > iNumThreads)
   {
      iLimit = iNumThreads;
   }
   
   printf("BigThreads biggest %d threads:\n", iLimit);
   
   for(iThreadNum = 0; iThreadNum < iLimit; iThreadNum++)
   {
      pMessage = &pThreadList[iThreadNum];
	
      printf("BigThreads thread %d(from %d, %s), %d messages (total size %d bytes)\n", pMessage->m_iID, pMessage->m_iFromID, pMessage->m_szSubject, pMessage->m_iCount, pMessage->m_iSize);
   }
   
   printf("BigThreads exit true, %d threads\n", iNumThreads);
   return true;
}
示例#17
0
//------------------------------------------------------------
static void
writeGraphics(BookCaseDB &db, const char *thisBook, DBCursor &gr_cursor,
	      int compressed, char *comp_agent)
{
  DBTable *out = db.DB::table(DATABASE_STDIO,
			      GRAPHIC_CODE, BT_NUM_GRAPHIC_FIELDS,
			      DB::CREATE);

  const char *aBook;
  const char *gid;
  const char *name;
  const char *version;
  const char *typeInfo;
  const char *data;
  int len;
  const char *title;
  
  while(gr_cursor.next(STRING_CODE, &aBook,
		       STRING_CODE, &gid,
		       STRING_CODE, &name,
		       STRING_CODE, &version,
		       STRING_CODE, &typeInfo,
		       -STRING_CODE, &data, &len,
		       STRING_CODE, &title,
		       NULL)){


    if(strcmp(aBook, thisBook) != 0){ /* book id has changed! We're done... */
      gr_cursor.undoNext();
      break;
    }

#ifdef FISH_DEBUG
    DBUG_PRINT("Graphics", ("Graphics data for: ::%s `%.40s...' \n",
			    gid, data));
#endif

    if ( typeInfo[0] - '0'  == GR_TYPE_POSTSCRIPT &&
	 compressed ) {

      out->insert(STRING_CODE, gid,
		  STRING_CODE, name,
		  STRING_CODE, version,
		  STRING_CODE, typeInfo,
		  -COMPRESSED_STRING_CODE, comp_agent, data, len,
		  STRING_CODE, title,
		  NULL);
    }
    else {
      out->insert(STRING_CODE, gid,
		  STRING_CODE, name,
		  STRING_CODE, version,
		  STRING_CODE, typeInfo,
		  -STRING_CODE, data, len,
		  STRING_CODE, title,
		  NULL);
    }
  }

  delete out;

}