コード例 #1
0
ファイル: simple_stable.cpp プロジェクト: nathansgreen/anvil
int simple_stable::init(int dfd, const char * name, const params & config, sys_journal * sysj)
{
	int r = -1;
	params meta_config, data_config;
	const dtable_factory * meta = dtable_factory::lookup(config, "meta");
	const ctable_factory * data = ctable_factory::lookup(config, "data");
	if(md_dfd >= 0)
		deinit();
	assert(column_map.empty());
	if(!meta || !data)
		return -ENOENT;
	if(!config.get("meta_config", &meta_config, params()))
		return -EINVAL;
	if(!config.get("data_config", &data_config, params()))
		return -EINVAL;
	md_dfd = openat(dfd, name, O_RDONLY);
	if(md_dfd < 0)
		return md_dfd;
	dt_meta = meta->open(md_dfd, "st_meta", meta_config, sysj);
	if(!dt_meta)
		goto fail_meta;
	ct_data = data->open(md_dfd, "st_data", data_config, sysj);
	if(!ct_data)
		goto fail_data;
	
	/* check sanity? */
	r = load_columns();
	if(r < 0)
		goto fail_check;
	
	return 0;
	
fail_check:
	delete ct_data;
fail_data:
	dt_meta->destroy();
fail_meta:
	close(md_dfd);
	md_dfd = -1;
	return r;
}
コード例 #2
0
II_EXTERN II_VOID
IIapi_loadColumns
(
    IIAPI_STMTHNDL	*stmtHndl,
    IIAPI_GETCOLPARM	*getColParm,
    IIAPI_MSG_BUFF	*msgBuff
)
{
    /*
    ** If no data available or request complete, we be done!
    */
    if ( msgBuff->length < 1  ||  ! stmtHndl->sh_colFetch  ||
	 getColParm->gc_rowsReturned >= getColParm->gc_rowCount )
    {
	IIAPI_TRACE( IIAPI_TR_DETAIL )
	    ( "IIapi_loadColumns: nothing to do\n" );
	return;
    }

    IIAPI_TRACE( IIAPI_TR_DETAIL )
	( "IIapi_loadColumns: converting tuple data to API format\n" );
    
    /*
    ** Loop for each row in the request.
    */
    do
    {
	/*
	** Process columns in the current row.  The current
	** column request should not span rows, but may be
	** fewer than the remaining columns in the row.  If
	** this is a multi-row fetch, we will reset the
	** column request for the next row after processing
	** the current row.  The current row request will
	** either be satisfied, or the tuple data will be
	** exhausted.
	*/
	load_columns( stmtHndl, getColParm, msgBuff );

	/*
	** If there are still columns to be processed in
	** the current request, exit to get more data.
	*/
	if ( stmtHndl->sh_colFetch )  break;

	/*
	** We have completed the request for the current row.
	** We bump the number of rows returned since we either
	** completed a row or completed a partial fetch of a
	** row.  We will either exit at this point or move
	** on to the next row.
	*/
	getColParm->gc_rowsReturned++;

	/*
	** Check to see if we have completed a row.
	*/
	if ( stmtHndl->sh_colIndex >= stmtHndl->sh_colCount )
	{
	    /*
	    ** For cursors, decrement the remaining row count now
	    ** that a row has been completed.
	    */
	    if ( stmtHndl->sh_flags & IIAPI_SH_CURSOR )
		stmtHndl->sh_rowCount--;

	    /*
	    ** Set the column index for the start of the next row.
	    ** If there are more rows in the request, set the 
	    ** column fetch count for the next row.
	    */
	    stmtHndl->sh_colIndex = 0;

	    if ( getColParm->gc_rowsReturned < getColParm->gc_rowCount )
		stmtHndl->sh_colFetch = stmtHndl->sh_colCount;
	}

    } while( stmtHndl->sh_colFetch );

    return;
}