/// 填充MysqlData数据 /// \param mysql MYSQL*参数 /// \retval true 成功 /// \retval false 失败 bool MysqlData::fill_data( MYSQL *mysql ) { if ( mysql == NULL ) return false; // clean if ( _mysqlres != NULL ) mysql_free_result( _mysqlres ); _mysqlres = 0; _curpos = 0; // return to first position _field_pos.clear(); // clean field pos cache // fill data _mysqlres = mysql_store_result( mysql ); if ( _mysqlres != NULL ) { _rows = mysql_num_rows( _mysqlres ); _cols = mysql_num_fields( _mysqlres ); _mysqlfields = mysql_fetch_fields( _mysqlres ); // init first data mysql_data_seek( _mysqlres, 0 ); _mysqlrow = mysql_fetch_row( _mysqlres ); return true; } return false; }
/// 返回指定位置的MysqlData数据行 /// \param row 数据行位置,默认为当前纪录位置, /// 当前纪录位置由first(),prior(),next(),last(),find()函数操纵,默认为0 /// \return 返回值类型为MysqlDataRow,即map<string,string> MysqlDataRow MysqlData::get_row( const long row ) { MysqlDataRow datarow; string field; size_t rowpos; if ( row < 0 ) rowpos = _curpos; else rowpos = row; if( _mysqlres!=NULL && rowpos<_rows ) { if ( rowpos != _curpos ) { if ( rowpos != _curpos+1 ) mysql_data_seek( _mysqlres, rowpos ); _mysqlrow = mysql_fetch_row( _mysqlres ); } if ( _mysqlrow != NULL ) { _curpos = rowpos; // log current cursor for ( size_t i=0; i<_cols; ++i ) { field = this->field_name( i ); if ( field!="" && _mysqlrow[i]!=NULL ) datarow.insert( MysqlDataRow::value_type(field,_mysqlrow[i]) ); } } } return datarow; }
VALUE db_mysql_result_each(VALUE self) { MYSQL_STMT *s; MYSQL_ROW data; size_t *lengths, row, col; Result *r = db_mysql_result_handle(self); if (r->statement && !NIL_P(r->statement)) return db_mysql_result_from_statement_each(self); if (!r->r) return Qfalse; mysql_data_seek(r->r, 0); for (row = 0; row < r->selected; row++) { VALUE tuple = rb_hash_new(); data = mysql_fetch_row(r->r); lengths = mysql_fetch_lengths(r->r); for (col = 0; col < (size_t)RARRAY_LEN(r->fields); col++) { if (!data[col]) { rb_hash_aset(tuple, rb_ary_entry(r->fields, col), Qnil); } else { rb_hash_aset(tuple, rb_ary_entry(r->fields, col), typecast_detect(data[col], lengths[col], NUM2INT(rb_ary_entry(r->types, col)))); } } rb_yield(tuple); } return Qtrue; }
/** Iterate over all tuples in the list */ static VALUE rdo_mysql_tuple_list_each(VALUE self) { RDOMySQLTupleList * list; Data_Get_Struct(self, RDOMySQLTupleList, list); if (!rb_block_given_p() || list->res == NULL) { return self; } mysql_data_seek(list->res, 0); unsigned int nfields = mysql_num_fields(list->res); MYSQL_FIELD * fields = mysql_fetch_fields(list->res); MYSQL_ROW row; while ((row = mysql_fetch_row(list->res))) { unsigned long * lengths = mysql_fetch_lengths(list->res); VALUE hash = rb_hash_new(); unsigned int i = 0; for (; i < nfields; ++i) { rb_hash_aset(hash, ID2SYM(rb_intern(fields[i].name)), rdo_mysql_cast_value(row[i], lengths[i], fields[i], list->encoding)); } rb_yield(hash); } return self; }
void TL_Mysql::TL_MysqlRes::dataSeek(long long offset) { if (offset >= _rows_num && _rows_num > 0) offset = _rows_num - 1; if (offset < 0) offset = 0; mysql_data_seek(_result, offset); }
bool CMySQL::SeekToFirstRow() { if ( !m_pResult ) return false; mysql_data_seek( m_pResult, 0 ); return true; }
void CDBSrcMySql::First() { if (m_QueryResult != NULL) { mysql_data_seek(m_QueryResult, 0); m_Row = mysql_fetch_row(m_QueryResult); m_nCurrField = 0; } }
void CSql::first(void) { if ( m_hResult != NULL ) { mysql_data_seek( m_hResult, 0 ); mysql_field_seek( m_hResult, 0 ); next(); } }
void tGroupGlueList(void) { MYSQL_RES *res; MYSQL_ROW field; ExttGroupGlueListSelect(); MYSQL_RUN_STORE(res); guI=mysql_num_rows(res); PageMachine("tGroupGlueList",1,"");//1 is auto header list guMode. Opens table! //Filter select drop down ExttGroupGlueListFilter(); printf("<input type=text size=16 name=gcCommand maxlength=98 value=\"%s\" >",gcCommand); printf("</table>\n"); printf("<table bgcolor=#9BC1B3 border=0 width=100%%>\n"); printf("<tr bgcolor=black>" "<td><font face=arial color=white>uGroupGlue" "<td><font face=arial color=white>uGroup" "<td><font face=arial color=white>uZone" "<td><font face=arial color=white>uResource</tr>"); mysql_data_seek(res,guStart-1); for(guN=0;guN<(guEnd-guStart+1);guN++) { field=mysql_fetch_row(res); if(!field) { printf("<tr><td><font face=arial,helvetica>End of data</table>"); Footer_ism3(); } if(guN % 2) printf("<tr bgcolor=#BBE1D3>"); else printf("<tr>"); printf("<td><input type=submit name=ED%s value=Edit> %s<td>%s<td>%s<td>%s</tr>" ,field[0] ,field[0] ,ForeignKey("tGroup","cLabel",strtoul(field[1],NULL,10)) ,ForeignKey("tZone","cLabel",strtoul(field[2],NULL,10)) ,ForeignKey("tResource","cLabel",strtoul(field[3],NULL,10)) ); } printf("</table></form>\n"); Footer_ism3(); }//tGroupGlueList()
void summary_stats (MYSQL_RES *res_set, unsigned int col_num) { MYSQL_FIELD *field; MYSQL_ROW row; unsigned int n, missing; double val, sum, sum_squares, var; /* verify data requirements: column must be in range and numeric */ if (col_num < 0 || col_num >= mysql_num_fields (res_set)) { print_error (NULL, "illegal column number"); return; } mysql_field_seek (res_set, col_num); field = mysql_fetch_field (res_set); if (!IS_NUM (field->type)) { print_error (NULL, "column is not numeric"); return; } /* calculate summary statistics */ n = 0; missing = 0; sum = 0; sum_squares = 0; mysql_data_seek (res_set, 0); while ((row = mysql_fetch_row (res_set)) != NULL) { if (row[col_num] == NULL) missing++; else { n++; val = atof (row[col_num]); /* convert string to number */ sum += val; sum_squares += val * val; } } if (n == 0) printf ("No observations\n"); else { printf ("Number of observations: %u\n", n); printf ("Missing observations: %u\n", missing); printf ("Sum: %g\n", sum); printf ("Mean: %g\n", sum / n); printf ("Sum of squares: %g\n", sum_squares); var = ((n * sum_squares) - (sum * sum)) / (n * (n - 1)); printf ("Variance: %g\n", var); printf ("Standard deviation: %g\n", sqrt (var)); } }
int zc_mysqlrec_reset(zcDBRec *rec) { zcMySQLRec *mrec = (zcMySQLRec*)rec; if (NULL == mrec->res) return -1; mrec->_pos = 0; mysql_data_seek(mrec->res, mrec->_pos); return 0; }
static PyObject* wsql_result_data_seek(wsql_result *self, PyObject *args) { unsigned int row; if (!PyArg_ParseTuple(args, "i:data_seek", &row)) return NULL; CHECK_RESULT(self, NULL); mysql_data_seek(self->result, row); Py_RETURN_NONE; }
//----------------------------------------------------------------------------- // 描述: 将游标指向起始位置(第一条记录之前) //----------------------------------------------------------------------------- bool MySqlDataSet::rewind() { if (getRecordCount() > 0) { mysql_data_seek(res_, 0); return true; } else return false; }
void CMySQLQuery::dataSeek(ulong offset) { #ifdef DEBUG qDebug("CMySQLQuery::dataSeek()"); #endif check_pending_event = 0; if (!isResultNull()) mysql_data_seek(mysql_res, offset); }
static int dbd_mysql_get_row(apr_pool_t *pool, apr_dbd_results_t *res, apr_dbd_row_t **row, int rownum) { MYSQL_ROW r = NULL; int ret = 0; if (res->statement) { if (res->random) { if (rownum > 0) { mysql_stmt_data_seek(res->statement, (my_ulonglong) --rownum); } else { return -1; /* invalid row */ } } ret = mysql_stmt_fetch(res->statement); switch (ret) { case 1: ret = mysql_stmt_errno(res->statement); break; case MYSQL_NO_DATA: ret = -1; break; default: ret = 0; /* bad luck - get_entry will deal with this */ break; } } else { if (res->random) { if (rownum > 0) { mysql_data_seek(res->res, (my_ulonglong) --rownum); } else { return -1; /* invalid row */ } } r = mysql_fetch_row(res->res); if (r == NULL) { ret = -1; } } if (ret == 0) { if (!*row) { *row = apr_palloc(pool, sizeof(apr_dbd_row_t)); } (*row)->row = r; (*row)->res = res; (*row)->len = mysql_fetch_lengths(res->res); } else { apr_pool_cleanup_run(res->pool, res->res, free_result); } return ret; }
int OffsetRecordResult(MYSQL_RES *pResult, int nOffset) { if (!pResult || nOffset < 0) { ErrorInfor("OffsetRecordResult", ERROR_ARGNULL); return 0; } mysql_data_seek(pResult, nOffset); return 1; }
bool CDBCmd::MoveFirst() { if (m_res == NULL) return false; mysql_data_seek(m_res, 0); m_row = mysql_fetch_row(m_res); if (m_row == NULL) return false; return true; }
/* Need to assemble a 64-bit integer to send to MySQL */ DLLEXPORT void clsql_mysql_data_seek (MYSQL_RES* res, unsigned int offset_high32, unsigned int offset_low32) { my_ulonglong offset; offset = offset_high32; offset = offset << 32; offset += offset_low32; mysql_data_seek (res, offset); }
char *DBget_field(MYSQL_RES *result, int rownum, int fieldnum) { MYSQL_ROW row; mysql_data_seek(result, rownum); row=mysql_fetch_row(result); if(row == NULL) { printf("Error while mysql_fetch_row():Error [%s] Rownum [%d] Fieldnum [%d]\n", mysql_error(&mysql), rownum, fieldnum ); exit(-1); } return row[fieldnum]; }
void tNASGroupList(void) { MYSQL_RES *res; MYSQL_ROW field; ExttNASGroupListSelect(); mysql_query(&gMysql,gcQuery); if(mysql_error(&gMysql)[0]) htmlPlainTextError(mysql_error(&gMysql)); res=mysql_store_result(&gMysql); guI=mysql_num_rows(res); PageMachine("tNASGroupList",1,"");//1 is auto header list guMode. Opens table! //Filter select drop down ExttNASGroupListFilter(); printf("<input type=text size=16 name=gcCommand maxlength=98 value=\"%s\" >",gcCommand); printf("</table>\n"); printf("<table bgcolor=#9BC1B3 border=0 width=100%%>\n"); printf("<tr bgcolor=black><td><font face=arial,helvetica color=white>uNAS<td><font face=arial,helvetica color=white>uServer</tr>"); mysql_data_seek(res,guStart-1); for(guN=0;guN<(guEnd-guStart+1);guN++) { field=mysql_fetch_row(res); if(!field) { printf("<tr><td><font face=arial,helvetica>End of data</table>"); Footer_ism3(); } if(guN % 2) printf("<tr bgcolor=#BBE1D3>"); else printf("<tr>"); printf("<td>%s<td>%s</tr>" ,ForeignKey("tNAS","cLabel",strtoul(field[0],NULL,10)) ,ForeignKey("tServer","cLabel",strtoul(field[1],NULL,10)) ); } printf("</table></form>\n"); Footer_ism3(); }//tNASGroupList()
void DBDataSet::moveFirst() { for (m_iter = m_results.begin(); m_iter != m_results.end(); ++m_iter) { if (*m_iter && mysql_num_rows(*m_iter) > 0) { mysql_data_seek(*m_iter, 0); m_row = mysql_fetch_row(*m_iter); m_lengths = mysql_fetch_lengths(*m_iter); ASSERT(m_row); ASSERT(m_lengths); return; } } m_row = NULL; m_lengths = NULL; }
CharString DatabaseMYSQL::data(QueryHandle hQuery, int n, int f ) const { QueryResult * pQuery = (QueryResult *)hQuery; if ( pQuery == NULL || pQuery->pResult == NULL ) return ""; if ( n < 0 || n >= (int)rows( hQuery ) ) return ""; if ( f < 0 || f >= (int)fields( hQuery ) ) return ""; mysql_data_seek( pQuery->pResult, n ); MYSQL_ROW row = mysql_fetch_row( pQuery->pResult ); return CharString( row[f] ? row[f] : "" ); }
//====================================================================================================================== void DatabaseImplementationMySql::ResetRowIndex(DatabaseResult* result, uint64 index) { if(!result) { gLogger->log(LogManager::CRITICAL,"Bad Ptr 'DatabaseResult* result' at DatabaseImplementationMySql::ResetRowIndex."); return; } MYSQL_RES* temp = (MYSQL_RES*)result->getResultSetReference(); if(!temp) { gLogger->log(LogManager::CRITICAL,"Bad Ptr '(MYSQL_RES*)result->getResultSetReference()' at DatabaseImplementationMySql::ResetRowIndex."); return; } mysql_data_seek(temp, index); }
char *MADB_GetDefaultColumnValue(MYSQL_RES *res, const char *Column) { MYSQL_ROW row; if (!res->row_count) return NULL; mysql_data_seek(res, 0); while ((row= mysql_fetch_row(res))) { if (_stricmp(row[0], Column) == 0) return _strdup(row[1]); } return NULL; }
std::vector<std::string> Mysql::getData(size_t nbLine) { MYSQL_ROW row; std::vector<std::string> tab; long unsigned int *lengths; mysql_data_seek(m_result, nbLine); row = mysql_fetch_row(m_result); if (!row) return tab; lengths = mysql_fetch_lengths(m_result); for (size_t i = 0; i < m_nbFields; ++i) tab.push_back(std::string(row[i], lengths[i])); return tab; }
std::string MySqlResult::get(uint32_t iRow, uint32_t iField) { if (iRow >= m_iRows || iField >= m_iFields) { return std::string(); } mysql_data_seek(m_pRes, iRow); MYSQL_ROW row = mysql_fetch_row(m_pRes); if (row == NULL) { return std::string(); } if (row[iField] == NULL) { return std::string(); } unsigned long* length = mysql_fetch_lengths(m_pRes); return std::string(row[iField], length[iField]); }
bool MySQLResult::seekRow(int64_t row) { if (row < 0 || row >= getRowCount()) { raise_warning("Unable to jump to row %" PRId64 " on MySQL result index %d", row, o_getId()); return false; } if (!m_localized) { mysql_data_seek(m_res, (my_ulonglong)row); } else { m_current_row = m_rows->begin(); for (int i = 0; i < row; i++) m_current_row++; m_row_ready = false; } return true; }
/// 返回指定位置的MysqlData数据 /// \param row 数据行位置,默认为0 /// \param col 数据列位置,默认为0 /// \return 返回数据,不存在则返回空字符串 string MysqlData::get_data( const size_t row, const size_t col ) { if( _mysqlres!=NULL && row<_rows && col<_cols ) { if ( static_cast<long>(row) != _fetched ) { if ( row != _curpos+1 ) mysql_data_seek( _mysqlres, row ); _mysqlrow = mysql_fetch_row( _mysqlres ); _fetched = static_cast<long>( row ); } if ( _mysqlrow!=NULL && _mysqlrow[col]!=NULL ) { _curpos = row; // log current cursor return string( _mysqlrow[col] ); } } return string( "" ); }
zcDBRec* zc_mysqlrec_new(void *stmt) { zcMySQLRec *mrec = (zcMySQLRec*)zc_malloc(sizeof(zcMySQLRec)); memset(mrec, 0, sizeof(zcMySQLRec)); mrec->res = stmt; mrec->_fields = 0; mrec->_rows = 0; mrec->_pos = 0; mrec->row = NULL; mrec->_get_row_next = 0; mrec->fieldmap = zc_dict_new(8); if (stmt) { mrec->_fields = mysql_num_fields(mrec->res); mrec->_rows = mysql_num_rows(mrec->res); mysql_data_seek(mrec->res, mrec->_pos); MYSQL_FIELD *fields; fields = mysql_fetch_fields(mrec->res); long i; for (i = 0; i < mrec->_fields; i++) { //mrec->fieldmap[fields[i].name] = i; zc_dict_add(mrec->fieldmap, fields[i].name, 0, (void*)i); } } mrec->del = zc_mysqlrec_delete; mrec->reset = zc_mysqlrec_reset; mrec->row_next = zc_mysqlrec_row_next; mrec->field_int_pos = zc_mysqlrec_field_int_pos; mrec->field_int = zc_mysqlrec_field_int; mrec->field_int64_pos = zc_mysqlrec_field_int64_pos; mrec->field_int64 = zc_mysqlrec_field_int64; mrec->field_float_pos = zc_mysqlrec_field_float_pos; mrec->field_float = zc_mysqlrec_field_float; mrec->field_str_pos = zc_mysqlrec_field_str_pos; mrec->field_str = zc_mysqlrec_field_str; mrec->field_blob_pos = zc_mysqlrec_field_blob_pos; mrec->field_blob = zc_mysqlrec_field_blob; mrec->fetchone = zc_mysqlrec_fetchone; return (zcDBRec*)mrec; }
bool embeddedResult::fetch(int i) { if(!d->driver) return false; if (isForwardOnly()) { // fake a forward seek if (at() < i) { int x = i - at(); while (--x && fetchNext()) {}; return fetchNext(); } else { return false; } } if (at() == i) return true; if (d->preparedQuery) { #if MYSQL_VERSION_ID >= 40108 mysql_stmt_data_seek(d->stmt, i); int nRC = mysql_stmt_fetch(d->stmt); if (nRC) { #ifdef MYSQL_DATA_TRUNCATED if (nRC == 1 || nRC == MYSQL_DATA_TRUNCATED) #else if (nRC == 1) #endif setLastError(qMakeStmtError(QCoreApplication::translate("embeddedResult", "Unable to fetch data"), QSqlError::StatementError, d->stmt)); return false; } #else return false; #endif } else { mysql_data_seek(d->result, i); d->row = mysql_fetch_row(d->result); if (!d->row) return false; } setAt(i); return true; }