Пример #1
0
void PgSqlDatatable::update()
{
    PGresult* res = (PGresult*)_res;

    // clear.
    this->clear();
    
    // update.
    rows_type& rows = this->_rows;
    cols_type& cols = this->_cols;
    
    uint const ncols = PQnfields(res);
    uint const nrows = PQntuples(res);
    cols.resize(ncols);
    rows.resize(nrows);
    
    // add cols.
    for (uint idx = 0; idx < ncols; ++idx)
    {
        char const* colname = PQfname(res, idx);
        cols[idx] = new variant_t(colname, core::copy);
    }
    
    // add rows.
    for (uint idx = 0; idx < nrows; ++idx)
    {
        DBMSqlDatatable::row_type* row = new DBMSqlDatatable::row_type();
        row->resize(ncols);
        
        for (uint jdx = 0; jdx < ncols; ++jdx)
        {
            char const* val = PQgetvalue(res, idx, jdx);
            (*row)[jdx] = new variant_t(val, core::copy);
        }
        
        rows[idx] = row;
    }
}
Пример #2
0
void MSSqlDatatable::update()
{
    // clear.
    this->clear();
    
# ifdef _FREETDS
    
    DBPROCESS* proc = (DBPROCESS*)_proc;
    
    // update.
    uint const ncols = dbnumcols(proc); 
    
    struct COL 						
    { 
        char *name; 
        char *buffer; 
        int type, size, status; 
    } *columns, *pcol;
    
    if ((columns = (COL*)calloc(ncols, sizeof(struct COL))) == NULL) {
        return;
    }
    
    RETCODE sta = 0;
    
    rows_type& rows = this->_rows;
    cols_type& cols = this->_cols;
    cols.resize(ncols);        
    
    //Read metadata and bind.  
    for (pcol = columns; pcol - columns < ncols; pcol++) {
        int c = (int)(pcol - columns + 1);
        
        pcol->name = dbcolname(proc, c);		
        pcol->type = dbcoltype(proc, c);
        pcol->size = dbcollen(proc, c);
        
        // add cols.
        cols[c - 1] = new variant_t(pcol->name, core::copy);
        
        if (SYBCHAR != pcol->type) {			
            pcol->size = dbwillconvert(pcol->type, SYBCHAR);
        }        
        
        if ((pcol->buffer = (char*)calloc(1, pcol->size + 1)) == NULL){
            break;
        }
        
        sta = dbbind(proc,
                     c,
                     NTBSTRINGBIND,	
                     pcol->size + 1,
                     (byte*)pcol->buffer);
        if (sta == FAIL) {
            break;
        }
        sta = dbnullbind(proc, 
                         c,
                         &pcol->status);	
        if (sta == FAIL) {
            break;
        }
    }
    
    // Get rows.
    while ((sta = dbnextrow(proc)) != NO_MORE_ROWS){	
        switch (sta) {
			case REG_ROW:
            {
                DBMSqlDatatable::row_type *row = new DBMSqlDatatable::row_type;
                row->resize(ncols);
                
				for (pcol=columns; pcol - columns < ncols; ++pcol) 
                {
                    int c = (int)(pcol - columns + 1);
					char const* buffer = pcol->status == -1 ? "" : pcol->buffer;
                    (*row)[c - 1] = new variant_t(buffer, core::copy);
				}
                
                rows.push_back(row);
            } break;
        }                
    }
    
    /* free metadata and data buffers */
    for (pcol=columns; pcol - columns < ncols; pcol++) {
        free(pcol->buffer);
    }
    free(columns);
    
# endif

# ifdef _MSSQL
	_RecordsetPtr& rcdset = *((_RecordsetPtr*)_proc);

	usize const ncols = (usize const)rcdset->Fields->GetCount();

	rows_type& rows = this->_rows;
	cols_type& cols = this->_cols;
	cols.resize(ncols);	

	// read cols.
	for (uint idx = 0; idx < ncols; ++idx)
	{
# ifdef NNT_DEBUG
		try {
# endif

		_bstr_t name = rcdset->Fields->GetItem((long)idx)->GetName();
		cols[idx] = new variant_t((char const*)name, core::copy);

# ifdef NNT_DEBUG
		} catch (_com_error& err) 	{
			_bstr_t msg = err.ErrorMessage();
			trace_msg((char const*)msg);
		}
# endif
	}

	// read rows.
	while (!rcdset->adoEOF)
	{
		row_type* row = new row_type;
		row->resize(ncols);

		for (uindex idx = 0; idx < ncols; ++idx)
		{
# ifdef NNT_DEBUG
			try {
# endif

			_bstr_t val = rcdset->GetCollect((long)idx);
			(*row)[idx] = new variant_t((char const*)val, core::copy);

# ifdef NNT_DEBUG
			} catch (_com_error& err) 	{
				_bstr_t msg = err.ErrorMessage();
				trace_msg((char const*)msg);
			}
# endif
		}

		rows.push_back(row);

		rcdset->MoveNext();
	}

# endif

}