Exemple #1
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;
}
Exemple #2
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;
}
void DBConnection_MYSQL::getTables(char *buffer, int *bufsize)
{
	int rowseplen = 1;
	char rowsep[] = "\n";
	if (!buffer) {
		*bufsize = 2500;
		return;
	}
	char tsql[] = "SHOW tables";
	DBCursor *newcursor = sqlQuery(tsql, NULL, 0, 0);
	if (newcursor) {
		char *result = buffer;
		char *resultptr = result;
		if (!newcursor->getEOF()){
			while (True){
				unsigned int colsize;
				char *coldata = newcursor->getFieldDataBinary(1,colsize);
				colsize = strlen(coldata);
				if (((resultptr-result) + colsize + rowseplen + 16 ) 
					> *bufsize)
					break;
				memcpy(resultptr,coldata,colsize);
				resultptr+=colsize;
				newcursor->next();
				if (newcursor->getEOF()) break;
				memcpy(resultptr,rowsep,rowseplen);
				resultptr+=rowseplen;
			}
		}
		deleteCursor(newcursor->GetID());
		*resultptr++ = '\0';
		*bufsize = resultptr-result;
	}
	newcursor = NULL;
}
Exemple #4
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;

}
Exemple #5
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;
  
}