コード例 #1
0
ファイル: db_impl.c プロジェクト: Zhouxiaoqing/kendylib
static result_set process_result_set (DB_HANDLE conn,MYSQL_RES *res_set)
{
	MYSQL_ROW     row;
	MYSQL_FIELD   **field;
	unsigned long field_num;
	unsigned int  i;
	mysql_field_seek (res_set, 0);
	field_num = mysql_num_fields (res_set);
	//field = malloc(sizeof(MYSQL_FIELD*)*field_num);
	//if(field == NULL)
	//	return NULL;
	result_set result = create_result_set(field_num);
	/*if(result == NULL)
	{
		free(field);
		return NULL;
	}*/
	while ((row = mysql_fetch_row (res_set)) != NULL)
	{
		mysql_field_seek (res_set, 0);
		for (i = 0; i < mysql_num_fields (res_set); i++)
		{			
			if (row[i] == NULL) 
				printf (" %s ","NULL");
			//else if (IS_NUM (field[i]->type)) 
			//	printf (" %s ",row[i]);
			else              
				printf (" %s ",row[i]);
		}
		fputc ('\n', stdout);
	}
	//free(field);
	return result;
}
コード例 #2
0
ファイル: util_mysql.cpp プロジェクト: zhdtty/storm_net
//测试用
void MySqlConn::printResult(MYSQL_RES* result) {
	int iFields = mysql_num_fields(result);

	MYSQL_FIELD* field;
	mysql_field_seek(result, 0);
	for (int i = 0; i < iFields; ++i) {
		field = mysql_fetch_field(result);
		if (i > 0) {
			printf("\t");
		}
		printf("%s", field->name);
	}
	printf("\n");


	MYSQL_ROW row;
	while ((row = mysql_fetch_row(result)) != NULL) {
		for (int i = 0; i < iFields; ++i) {
			if (i > 0) {
				printf("\t");
			}
			printf("%s", row[i] != NULL ? row[i] : "NULL");
		}
		printf("\n");
	}
}
コード例 #3
0
ファイル: database.cpp プロジェクト: samevers/dlg_service
CMysqlRow* CMysqlQuery::fetch()
{
	if( m_bEnd )
		return 0;

	if( !m_row.m_row )
	{
		m_row.m_row = mysql_fetch_row(m_pResult);
		m_row.m_lengths = mysql_fetch_lengths(m_pResult);
		m_row.m_fields = mysql_num_fields(m_pResult);
		mysql_field_seek(m_pResult, 0);
		unsigned int i;
		for( i=0; i<m_row.m_fields; i++ )
		{
			MYSQL_FIELD* field = mysql_fetch_field(m_pResult);
			m_row.m_types[i] = field->type;
			m_field_index.insert(std::pair<std::string, unsigned int>(field->name, i));
		}
	}
	else
	{
		m_row.m_row = mysql_fetch_row(m_pResult);
		//m_row.m_lengths = mysql_fetch_lengths(m_pResult);
	}
	if( !m_row.m_row )
	{
		clear();
		m_bEnd = true;
		return 0;
	}

	return &m_row;
}
コード例 #4
0
ファイル: qsql_mysql.cpp プロジェクト: aroraujjwal/qt3
QSqlRecordInfo QMYSQLDriver::recordInfo( const QSqlQuery& query ) const
{
    QSqlRecordInfo info;
    if ( !isOpen() )
	return info;
    if ( query.isActive() && query.isSelect() && query.driver() == this ) {
	QMYSQLResult* result =  (QMYSQLResult*)query.result();
	QMYSQLResultPrivate* p = result->d;
	if ( !mysql_errno( p->mysql ) ) {
	    for ( ;; ) {
		MYSQL_FIELD* field = mysql_fetch_field( p->result );
		if ( field ) {
		    info.append ( QSqlFieldInfo( QString( field->name ),
				qDecodeMYSQLType( (int)field->type, field->flags ),
				IS_NOT_NULL( field->flags ),
				(int)field->length,
				(int)field->decimals,
				QVariant(),
				(int)field->type ) );
		
		} else
		    break;
	    }
	}
	mysql_field_seek( p->result, 0 );
    }
    return info;
}
コード例 #5
0
ファイル: db_impl.c プロジェクト: Zhouxiaoqing/kendylib
struct field_metadatas *db_get_table_metadata(DB_HANDLE conn,const char *table)
{
	MYSQL_RES *res_set;
	res_set = mysql_list_fields(conn,table,NULL);
	if(res_set)
	{
		struct field_metadatas* metadatas = malloc(sizeof(struct field_metadatas));
		MYSQL_FIELD   **field;
		unsigned int  i;
		mysql_field_seek(res_set, 0);
		metadatas->size = mysql_num_fields(res_set);
		metadatas->_field_metadata = malloc(sizeof(struct field_metadata)*metadatas->size);
		field = malloc(sizeof(MYSQL_FIELD*)*metadatas->size);
		for (i = 0; i < metadatas->size; i++)
		{
			field[i] = mysql_fetch_field (res_set);
			strncpy(metadatas->_field_metadata[i].name,field[i]->name,NAME_CHAR_LEN);
			metadatas->_field_metadata[i].type = field[i]->type;
			metadatas->_field_metadata[i].max_length = field[i]->length;
			metadatas->_field_metadata[i].default_value = make_defaule_value(field[i]);
		}
		free(field);
		mysql_free_result (res_set);
		return metadatas;
	}
	print_error(conn, "Could not execute statement");
	return NULL;
}
コード例 #6
0
ファイル: mysql_client_fw.c プロジェクト: lanqiyi/CacheDB
static void my_print_result_metadata(MYSQL_RES *result)
{
 MYSQL_FIELD  *field;
 unsigned int i;
 size_t j;
 unsigned int field_count;

 mysql_field_seek(result, 0);
 if (!opt_silent)
 {
   fputc('\n', stdout);
   fputc('\n', stdout);
 }

 field_count= mysql_num_fields(result);
 for(i= 0; i< field_count; i++)
 {
   field= mysql_fetch_field(result);
   j= strlen(field->name);
   if (j < field->max_length)
   j= field->max_length;
   if (j < 4 && !IS_NOT_NULL(field->flags))
   j= 4;
   field->max_length= j;
 }
 if (!opt_silent)
 {
   my_print_dashes(result);
   fputc('\t', stdout);
   fputc('|', stdout);
 }

 mysql_field_seek(result, 0);
 for(i= 0; i< field_count; i++)
 {
   field= mysql_fetch_field(result);
   if (!opt_silent)
   fprintf(stdout, " %-*s |", (int) field->max_length, field->name);
 }
 if (!opt_silent)
 {
   fputc('\n', stdout);
   my_print_dashes(result);
 }
}
コード例 #7
0
ファイル: sql.cpp プロジェクト: quinsmpang/phone-code
void CSql::first(void)
{
	if ( m_hResult != NULL )
	{
		mysql_data_seek( m_hResult, 0 );
		mysql_field_seek( m_hResult, 0 );
		next();
	}
}
コード例 #8
0
ファイル: ext_mysql.cpp プロジェクト: 191919/hhvm
static Variant HHVM_FUNCTION(mysql_async_fetch_array, const Resource& result,
                                               int result_type /* = 1 */) {
  if ((result_type & PHP_MYSQL_BOTH) == 0) {
    throw_invalid_argument("result_type: %d", result_type);
    return false;
  }

  auto res = php_mysql_extract_result(result);
  if (!res) {
    return false;
  }

  MYSQL_RES* mysql_result = res->get();
  if (!mysql_result) {
    raise_warning("invalid parameter to mysql_async_fetch_array");
    return false;
  }

  MYSQL_ROW mysql_row = nullptr;
  int status = mysql_fetch_row_nonblocking(mysql_result, &mysql_row);
  // Last row, or no row yet available.
  if (status != NET_ASYNC_COMPLETE) {
    return false;
  }
  if (mysql_row == nullptr) {
    res->close();
    return false;
  }

  unsigned long *mysql_row_lengths = mysql_fetch_lengths(mysql_result);
  if (!mysql_row_lengths) {
    return false;
  }

  mysql_field_seek(mysql_result, 0);

  Array ret;
  MYSQL_FIELD *mysql_field;
  int i;
  for (mysql_field = mysql_fetch_field(mysql_result), i = 0; mysql_field;
       mysql_field = mysql_fetch_field(mysql_result), i++) {
    Variant data;
    if (mysql_row[i]) {
      data = mysql_makevalue(String(mysql_row[i], mysql_row_lengths[i],
                                    CopyString), mysql_field);
    }
    if (result_type & PHP_MYSQL_NUM) {
      ret.set(i, data);
    }
    if (result_type & PHP_MYSQL_ASSOC) {
      ret.set(String(mysql_field->name, CopyString), data);
    }
  }

  return ret;
}
コード例 #9
0
ファイル: summary_stats.c プロジェクト: dongxiaozhen/lbbNote
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));
  }
}
コード例 #10
0
ファイル: mysql_client_fw.c プロジェクト: lanqiyi/CacheDB
static int my_process_result_set(MYSQL_RES *result)
{
 MYSQL_ROW    row;
 MYSQL_FIELD  *field;
 unsigned int i;
 unsigned int row_count= 0;

 if (!result)
 return 0;

 my_print_result_metadata(result);

 while ((row= mysql_fetch_row(result)) != NULL)
 {
   mysql_field_seek(result, 0);
   if (!opt_silent)
   {
     fputc('\t', stdout);
     fputc('|', stdout);
   }

   for(i= 0; i< mysql_num_fields(result); i++)
   {
     field= mysql_fetch_field(result);
     if (!opt_silent)
     {
       if (row[i] == NULL)
       fprintf(stdout, " %-*s |", (int) field->max_length, "NULL");
       else if (IS_NUM(field->type))
       fprintf(stdout, " %*s |", (int) field->max_length, row[i]);
       else
       fprintf(stdout, " %-*s |", (int) field->max_length, row[i]);
     }
   }
   if (!opt_silent)
   {
     fputc('\t', stdout);
     fputc('\n', stdout);
   }
   row_count++;
 }
 if (!opt_silent)
 {
   if (row_count)
   my_print_dashes(result);

   if (mysql_errno(mysql) != 0)
   fprintf(stderr, "\n\tmysql_fetch_row() failed\n");
   else
   fprintf(stdout, "\n\t%d %s returned\n", row_count,
   row_count == 1 ? "row" : "rows");
 }
 return row_count;
}
コード例 #11
0
void
MySQLDriver::getColumnNames( const void* result,
                             vector< MC2String >& colNames )
{
   MYSQL_FIELD* field;
   while ( (field = mysql_fetch_field( ( MYSQL_RES* )result )) ) {
         colNames.push_back( field->name );
   }
   // Seek to the beginning of the row to reset the field cursor
   mysql_field_seek( ( MYSQL_RES* )result, 0 );
}
コード例 #12
0
ファイル: luamysql.c プロジェクト: hy0kl/lua-mysql
/**
* do fetch
*/
static int Lmysql_do_fetch (lua_State *L, lua_mysql_res *my_res, int result_type) {
    MYSQL_RES *res = my_res->res;
    unsigned long *lengths;

    MYSQL_ROW row = mysql_fetch_row(res);
    if (row == NULL) {
        lua_pushnil(L);  /* no more results */
        return 1;
    }

    lengths = mysql_fetch_lengths(res);


    if (result_type == MYSQL_NUM) {
        int i;
        lua_newtable(L); /* result */

        for (i = 0; i < my_res->numcols; i++) {
            luaM_pushvalue (L, row[i], lengths[i]);
            lua_rawseti (L, -2, i+1);
        }
    }
    else {

        int i,j;
        MYSQL_FIELD *field;
        /* Check if colnames exists */
        lua_newtable(L); /* result */

	mysql_field_seek(my_res->res, 0);
	for (field = mysql_fetch_field(my_res->res), i = 0;
                 field;
                 field = mysql_fetch_field(my_res->res), i++)
        {
            /* push the field name */
            luaM_pushvalue (L, field->name, field->name_length);
            /* Actually push the value */
            luaM_pushvalue (L, row[i], lengths[i]);
            lua_rawset (L, -3);
        }

        if (result_type == MYSQL_BOTH) {
            /* Copy values to numerical indices */
            for (j = 0; j < my_res->numcols; j++) {
                lua_pushnumber(L, j+1);
                luaM_pushvalue (L, row[j], lengths[j]);
                lua_rawset (L, -3);
            }
        }
    }
    return 1;
}
コード例 #13
0
void GameDBChannel::SelectFriendList(int64_t userNo, int* friendCount, NickNameInfo* nickNameInfoList)
{
    char query[256] = { 0, };
    
    sprintf(query,
            SELECT_FRIEND_QUERY,
            userNo, userNo);
    
    
    MYSQL_RES* resultSet = NULL;
    _dbConn.ProcessResultQuery(query, &resultSet);
    
    if (resultSet)
    {
        MYSQL_ROW row;
        
        int i = 0;
        
        while ((row = mysql_fetch_row(resultSet)) != NULL)
        {
            mysql_field_seek(resultSet, 0);
            
            if (mysql_num_fields(resultSet) != USER_FIELD_COUNT)
            {
                ErrorLog("the retrieved field is incorrect, fields:%d", mysql_num_fields(resultSet));
                mysql_free_result(resultSet);
                return ;
            }
            
            if (atoll(row[FRIEND_F1]) == userNo)
            {
                strcpy(nickNameInfoList[i].nickName, row[FRIEND_F1]);
                nickNameInfoList[i].nickNameLen = strlen(row[FRIEND_F1]);
            }
            else if (atoll(row[FRIEND_F2]) == userNo)
            {
                strcpy(nickNameInfoList[i].nickName, row[FRIEND_F2]);
                nickNameInfoList[i].nickNameLen = strlen(row[FRIEND_F2]);
            }
            else
            {
                ErrorLog("??");
            }
            
            i++;
        }
        
        *friendCount = i;
        
        mysql_free_result(resultSet);
    }
}
コード例 #14
0
//---------------------------------------------------------------------------
deque<string> fill_rows(MYSQL_RES *res)
{
 MYSQL_ROW row;
 deque<string> rows;

 while ((row=mysql_fetch_row(res)) != 0)
 {
   mysql_field_seek(res,0);
   for (unsigned int i=0 ; i < mysql_num_fields(res); i++)
    rows.push_back(row[i]);
 }
 return rows;
}
コード例 #15
0
map<string, string> CDatabase_Connection::fetch_assoc()
{
	map<string, string> daten;
	daten["error"] = "false";
	try
	{
		if(this->initialised == false)
			throw "No query found!";
        if(mysql_res == NULL)
            throw "Query failed!";
		mysql_field_seek(mysql_res, 0); //!
		if(mysql_affected_rows(&my) == 0)
			throw "Nothing found! Is your request right??";
		if((row = mysql_fetch_row (mysql_res)) != NULL)
		{
			mysql_field_seek (mysql_res, 0);

			for (i = 0; i < mysql_num_fields (mysql_res); i++)
			{
				field = mysql_fetch_field (mysql_res);
				if (row[i] == NULL)
                    daten[field->name] = "";
                else
                    daten[field->name] = row[i];
			}
		}
	}
	catch(char* error)
	{
		cerr << error << endl;
		daten["error"] = "true";
	}
	catch(...)
	{
		daten["error"] = "true";
	}

	return daten;
}
コード例 #16
0
ファイル: mysql_common.cpp プロジェクト: 2bj/hhvm
bool MySQLResult::seekField(int64_t field) {
  if (field < 0 || field >= getFieldCount()) {
    raise_warning("Field %" PRId64 " is invalid for MySQL result index %d",
                    field, o_getId());
    return false;
  }

  if (!m_localized) {
    mysql_field_seek(m_res, (MYSQL_FIELD_OFFSET)field);
  }
  m_current_field = field - 1;
  return true;
}
コード例 #17
0
ファイル: lmtmysql.c プロジェクト: LaHaine/lmt
static int
_verify_type (MYSQL_RES *res, int i, enum enum_field_types t)
{
    int retval = -1;
    MYSQL_FIELD *field;

    mysql_field_seek(res, i);
    if (!(field = mysql_fetch_field(res)))
        goto done;
    if (field->type != t)
        goto done;
    retval = 0;
done:
    return retval;
}
コード例 #18
0
ファイル: ADBRow.cpp プロジェクト: gottafixthat/tacc
int ADBRow::loadRow(MYSQL_RES *queryRes)
{
    int             ret = 0;
    MYSQL_ROW       rawRow;
    unsigned long   *rowLengths;
    MYSQL_FIELD     *curField;

    ADBDebugMsg(7, "ADBRow::loadRow clearing currently loaded data...");
    // clearRow();

    ADBDebugMsg(7, "ADBRow::loadRow determining field count...");
    numFields = mysql_num_fields(queryRes);
    
    // Now that we have the number of fields, we can proceed.
    if (numFields > 0) {
        rawRow = mysql_fetch_row(queryRes);
        if (rawRow) {
            rowLengths = (unsigned long *) mysql_fetch_lengths(queryRes);
            ADBDebugMsg(7, "ADBRow::loadRow fethcing %d fields...", numFields);
            mysql_field_seek(queryRes, 0);
            for (uint i = 0; i < numFields; i++) {
                // Instantiate the column class for this column
                if (!intRowDefined) columns[i] = new ADBColumn();

                // Get the field by number
                curField = mysql_fetch_field(queryRes);

                // Now, fill in the column name, its type, etc.
                columns[i]->setDebugLevel(debugLevel);
                columns[i]->define(i, curField, rawRow[i]);
            }
            intRowDefined = 1;
            ret = 1;
        }
    }
    
    if (debugLevel > 7 && intRowDefined && ret) {
        ADBDebugMsg(7, "ADBRow:  Loaded row with the following structure");
        for (uint i = 0; i < numFields ; i++) {
            ADBDebugMsg(7, "   Column[%d]->Name  = '%s'", i, columns[i]->ColumnName());
            ADBDebugMsg(7, "   Column[%d]->Table = '%s'", i, columns[i]->TableName());
            ADBDebugMsg(7, "   Column[%d]->Data  = '%s'", i, columns[i]->Data());
            ADBDebugMsg(7, "   Column[%d]->Type  = '%d'", i, columns[i]->DataType());
        }
    }

    return ret; 
}
コード例 #19
0
ファイル: mysql3.c プロジェクト: llxp/llxp
void print_line(MYSQL_RES *res) {
   MYSQL_FIELD   *field;
   unsigned int  i, j;

   mysql_field_seek (res, 0);
   /* erstes Zeichen der Linie */
   printf("+");
   for (i = 0; i < mysql_num_fields(res); i++) {
      field = mysql_fetch_field(res);
      /* max_length '-' Zeichen jeder Spalte ausgeben */
      for (j = 0; j < field->max_length + 2; j++)
         printf("-");
      /* am Ende der Spalte '+' ausgeben */
      printf("+");
   }
   printf("\n");
}
コード例 #20
0
ファイル: mysql_client_fw.c プロジェクト: lanqiyi/CacheDB
static void my_print_dashes(MYSQL_RES *result)
{
 MYSQL_FIELD  *field;
 unsigned int i, j;

 mysql_field_seek(result, 0);
 fputc('\t', stdout);
 fputc('+', stdout);

 for(i= 0; i< mysql_num_fields(result); i++)
 {
   field= mysql_fetch_field(result);
   for(j= 0; j < field->max_length+2; j++)
   fputc('-', stdout);
   fputc('+', stdout);
 }
 fputc('\n', stdout);
}
コード例 #21
0
ファイル: help.c プロジェクト: rezalas/riftshadow
void do_listhelp(CHAR_DATA *ch, char *argument)
{
	MYSQL		*conn;
	MYSQL_FIELD	*field;
	MYSQL_ROW	row;
	MYSQL_RES 	*res_set;
	char buf[MSL], query[MSL], arg1[MSL];
	if(!str_cmp(argument,""))
	{
		send_to_char("Syntax: listhelp all\n\r",ch);
		send_to_char("        listhelp <field> <value>\n\r",ch);
		send_to_char("        Valid fields are: id, title, skill, minlevel, helpdata\n\r",ch);
		send_to_char("        You can search for substrings by entering them normally.\n\r",ch);
		return;
	}
	argument = one_argument(argument,arg1);
	if(!str_cmp(arg1,"ALL"))
		sprintf(query, "select * from helpfiles");
	else
		sprintf(query, "select * from helpfiles where %s RLIKE '%s'", arg1, argument);
	conn = open_conn();
	if(!conn)
		return send_to_char("Error opening help database.\n\r",ch);
	mysql_query (conn, query);
	res_set = mysql_store_result (conn);
	if (res_set == NULL || mysql_field_count(conn)<1)
			send_to_char("Error accessing results.\n\r",ch);
	else
	{
		while((row = mysql_fetch_row (res_set)) != NULL)
		{
			mysql_field_seek (res_set, 0);
			field	= mysql_fetch_field (res_set);
                	sprintf(buf, "Help ID: %s\n\rHelp Title: %s\n\rRequired Skill: %s\n\rMinimum Level: %s\n\r",
                        	row[0], row[1], row[2], row[3]);
                	send_to_char(buf,ch);
        	        sprintf(buf,"Help Text:\n\r%s\n\r", row[4]);
	                send_to_char(buf,ch);
		}
		mysql_free_result(res_set);
	}
	do_disc (conn);
}
コード例 #22
0
ファイル: mysql_xml.c プロジェクト: savonix/dbrs2xml
static void
print_table_data_xml(MYSQL_RES *result, char *query_name)
{
  MYSQL_ROW   cur;
  MYSQL_FIELD *fields;
  mysql_field_seek(result,0);
  printf("<?xml version=\"1.0\"?>\n");
  printf("<");
  printf(query_name);
  printf(">\n");
  fields = mysql_fetch_fields(result);
  uint i;
  while ((cur = mysql_fetch_row(result)))
  {
    ulong *lengths=mysql_fetch_lengths(result);
    printf("\t<");
    printf(query_name);
    printf(">\n");
    for (i=0; i < mysql_num_fields(result); i++)
    {
      printf("\t\t<");
      printf(fields[i].name, (uint) strlen(fields[i].name));
      if (cur[i])
      {
        printf(">");
        printf(cur[i], lengths[i]);
        printf("</");
        printf(fields[i].name, (uint) strlen(fields[i].name));
        printf(">\n");
      }
      else
        printf("\" xsi:nil=\"true\" />\n");
    }
    (void) printf("\t</");
    (void) printf(query_name);
    (void) printf(">\n");

  }
  printf("</");
  printf(query_name);
  printf(">\n");

}
コード例 #23
0
ファイル: util_mysql.cpp プロジェクト: zhdtty/storm_net
MySqlResult::MySqlResult(MYSQL_RES* pRes)
	:m_pRes(pRes)
	,m_iRows(0)
	,m_iFields(0) {

	m_pRes = pRes;
	if (m_pRes == NULL) {
		return;
	}
	m_iRows   = mysql_num_rows(m_pRes);
	m_iFields = mysql_num_fields(m_pRes);

	MYSQL_FIELD* field;
	mysql_field_seek(m_pRes, 0);
	for (uint32_t i = 0; i < m_iFields; ++i) {
		field = mysql_fetch_field(m_pRes);
		m_mField2Index.insert(std::make_pair(field->name, i));
	}
}
コード例 #24
0
ファイル: qsql_mysql.cpp プロジェクト: aroraujjwal/qt3
QSqlRecord QMYSQLDriver::record( const QSqlQuery& query ) const
{
    QSqlRecord fil;
    if ( !isOpen() )
	return fil;
    if ( query.isActive() && query.isSelect() && query.driver() == this ) {
	QMYSQLResult* result =  (QMYSQLResult*)query.result();
	QMYSQLResultPrivate* p = result->d;
	if ( !mysql_errno( p->mysql ) ) {
	    for ( ;; ) {
		MYSQL_FIELD* f = mysql_fetch_field( p->result );
		if ( f ) {
		    QSqlField fi( QString((const char*)f->name), qDecodeMYSQLType( f->type, f->flags ) );
		    fil.append( fi  );
		} else
		    break;
	    }
	}
	mysql_field_seek( p->result, 0 );
    }
    return fil;
}
コード例 #25
0
ファイル: gsc_mysql.cpp プロジェクト: riicchhaarrd/libcod
int gsc_mysql_field_seek()
{
	int result;
	int offset;
	
	int helper = 0;
	helper += stackGetParamInt(1, &result);
	helper += stackGetParamInt(2, &offset);
	
	#if DEBUG_MYSQL
	printf_hide("gsc_mysql_field_seek(result=%d, offset=%d)\n", result, offset);
	#endif
	
	if (helper != 2)
	{
		printf_hide("scriptengine> wrongs args for mysql_field_seek(result, offset);\n");
		return stackPushUndefined();
	}

	int ret = mysql_field_seek((MYSQL_RES *)result, offset);
	return stackReturnInt(ret);
}
コード例 #26
0
/*for the SQL result formatter*/
void print_dashes (CHAR_DATA *ch, MYSQL_RES *res)
{
	MYSQL_FIELD *field;
	unsigned int i, j;
	char sbuf[MSL];
	int jic;


	mysql_field_seek (res, 0);
	sprintf (sbuf,"#G+#0");
	stc(sbuf, ch);
	for (i = 0; i < mysql_num_fields (res); i++)
	{
		field = mysql_fetch_field (res);
		if(!strcmp(field->name,"message_num"))
		{
			for (j = 0; j < 8 ; j++)
			{
				sprintf (sbuf,"#8-#0");
				stc(sbuf, ch);
			}
		}
		else if(!strcmp(field->name,"log_num"))
		{
			for (j = 0; j < strlen(field->name) +2; j++)
			{
				sprintf (sbuf,"#8-#0");
				stc(sbuf, ch);
			}
		}
		else if(!strcmp(field->name,"timestamp"))
		{
			for (j = 0; j < 17 ; j++)
			{
				sprintf (sbuf,"#8-#0");
				stc(sbuf, ch);
			}
		}
		else if(!strcmp(field->name,"entry_num"))
		{
			for (j = 0; j < 11 ; j++)
			{
				sprintf (sbuf,"#8-#0");
				stc(sbuf, ch);
			}
		}
		else if(field->max_length > 55)
		{
			for (j = 0; j < 55; j++)
			{
				sprintf (sbuf,"#8-#0");
				stc(sbuf, ch);
			}
		}
		else
		{
			for (j = 0; j < field->max_length + 2; j++)
			{
				sprintf (sbuf,"#8-#0");
				stc(sbuf, ch);
			}
		}
		sprintf (sbuf,"#G+#0");
		stc(sbuf, ch);
	}
	sprintf (sbuf,"\n");
	stc(sbuf, ch);
}
コード例 #27
0
void
process_result_set (CHAR_DATA *ch, MYSQL *db, MYSQL_RES *res)
{
	MYSQL_FIELD *field;
	MYSQL_ROW row;
	unsigned int i, c, col_len;
	
	char sbuf[MSL];
	/* determine column display widths */
	mysql_field_seek (res, 0);
	unsigned int clen[1000];
	for (i = 0; i < mysql_num_fields (res); i++)
	{	
		field = mysql_fetch_field (res);
		clen[i] = strlen (field->name);
		if (clen[i] < field->max_length)
			clen[i]=field->max_length;
		if (clen[i] < 4 && !IS_NOT_NULL (field->flags))
			clen[i] = 4; /* 4 = length of the word “NULL” */
		if(!strcmp(field->name,"timestamp"))
			clen[i] -= 18;
		
	}
	print_dashes (ch, res);
	mysql_field_seek (res, 0);
	for (i = 0; i < mysql_num_fields (res); i++)
	{
		field = mysql_fetch_field (res);
		sprintf (sbuf,"#8| #C%-*s #0", clen[i], field->name);
		stc(sbuf, ch);
	}
	sprintf (sbuf,"\n");
	stc(sbuf, ch);
	print_dashes (ch, res);
	while ((row = mysql_fetch_row (res)) != NULL)
	{
		mysql_field_seek (res, 0);
		for (i = 0; i < mysql_num_fields (res); i++)
		{
			field = mysql_fetch_field (res);
			if (row[i] == NULL)
			{
				sprintf (sbuf,"#8| %-*s #0", clen[i], "NULL");
				stc(sbuf, ch);
			}
			else if (IS_NUM (field->type))
			{	
				sprintf (sbuf,"#8| #R%*s #0", clen[i], row[i]);
				stc(sbuf, ch);
			}
			else
			{
					c = strlen(field->name);
					sprintf (sbuf,"#8| #W%-*s #0", clen[i], row[i]);
				
				stc(sbuf, ch);
			}
		}
		sprintf (sbuf,"\n");
		stc(sbuf, ch);
	}
	print_dashes (ch, res);
	sprintf (sbuf,"\n\r#R%lu #8Records returned#0\n\r", (unsigned long) mysql_num_rows (res));
	stc(sbuf, ch);
}
コード例 #28
0
ファイル: mysql_client_fw.c プロジェクト: lanqiyi/CacheDB
static int my_process_stmt_result(MYSQL_STMT *stmt)
{
 int         field_count;
 int         row_count= 0;
 MYSQL_BIND  buffer[MAX_RES_FIELDS];
 MYSQL_FIELD *field;
 MYSQL_RES   *result;
 char        data[MAX_RES_FIELDS][MAX_FIELD_DATA_SIZE];
 ulong       length[MAX_RES_FIELDS];
 my_bool     is_null[MAX_RES_FIELDS];
 int         rc, i;

 if (!(result= mysql_stmt_result_metadata(stmt))) /* No meta info */
 {
   while (!mysql_stmt_fetch(stmt))
   row_count++;
   return row_count;
 }

 field_count= MY_MIN(mysql_num_fields(result), MAX_RES_FIELDS);

 memset(buffer, 0, sizeof(buffer));
 memset(length, 0, sizeof(length));
 memset(is_null, 0, sizeof(is_null));

 for(i= 0; i < field_count; i++)
 {
   buffer[i].buffer_type= MYSQL_TYPE_STRING;
   buffer[i].buffer_length= MAX_FIELD_DATA_SIZE;
   buffer[i].length= &length[i];
   buffer[i].buffer= (void *) data[i];
   buffer[i].is_null= &is_null[i];
 }

 rc= mysql_stmt_bind_result(stmt, buffer);
 check_execute(stmt, rc);

 rc= 1;
 mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*)&rc);
 rc= mysql_stmt_store_result(stmt);
 check_execute(stmt, rc);
 my_print_result_metadata(result);

 mysql_field_seek(result, 0);
 while ((rc= mysql_stmt_fetch(stmt)) == 0)
 {
   if (!opt_silent)
   {
     fputc('\t', stdout);
     fputc('|', stdout);
   }
   mysql_field_seek(result, 0);
   for (i= 0; i < field_count; i++)
   {
     field= mysql_fetch_field(result);
     if (!opt_silent)
     {
       if (is_null[i])
       fprintf(stdout, " %-*s |", (int) field->max_length, "NULL");
       else if (length[i] == 0)
       {
	 data[i][0]= '\0';  /* unmodified buffer */
	 fprintf(stdout, " %*s |", (int) field->max_length, data[i]);
       }
       else if (IS_NUM(field->type))
       fprintf(stdout, " %*s |", (int) field->max_length, data[i]);
       else
       fprintf(stdout, " %-*s |", (int) field->max_length, data[i]);
     }
   }
   if (!opt_silent)
   {
     fputc('\t', stdout);
     fputc('\n', stdout);
   }
   row_count++;
 }
 DIE_UNLESS(rc == MYSQL_NO_DATA);
 if (!opt_silent)
 {
   if (row_count)
   my_print_dashes(result);
   fprintf(stdout, "\n\t%d %s returned\n", row_count,
   row_count == 1 ? "row" : "rows");
 }
 mysql_free_result(result);
 return row_count;
}
コード例 #29
0
ファイル: mysql3.c プロジェクト: llxp/llxp
void alle_daten_ausgeben(void) {
   unsigned int  i, col_len;
   MYSQL_ROW  row;
   MYSQL_RES  *res;
   MYSQL_FIELD  *field;

   /* jetzt die Anfrage an den Datenbankserver */
   mysql_real_query(mysql, "SELECT * FROM filmdaten",
      strlen("SELECT * FROM filmdaten"));
   check_error();
   /* Anfrage vom Server in die Struktur MYSQL_RES laden */
   res = mysql_store_result(mysql);
   check_error();

   /* offset = 0 bedeutet: auf den Anfang der Zeile setzen */
   mysql_field_seek (res, 0);

   /* Damit bei der Ausgabe ein einheitliches Bild entsteht,
    * sollen die Daten für die maximale Länge einer Spalte
    * bei jeder einzelnen (MYSQL_FIELD)-Spalte verändert werden. */
   for (i = 0; i < mysql_num_fields(res); i++) {
      field = mysql_fetch_field (res);
      /* Länge des Namens in der Spalte ermitteln */
      col_len = strlen (field->name);
      /* Ist die Länge des Elements in der Spalte kleiner als
         die maximale Länge ... */
      if (col_len < field->max_length)
      /* ... dann bekommt col_len den Wert der maximal
             erlaubten Länge der Spalte. */
         col_len = field->max_length;
      /* Für den Fall, dass eine Spalte keine Daten
         beinhaltet ... */
      if (col_len < 4 && !IS_NOT_NULL (field->flags))
      /* ... bekommt col_len den Wert 4 für den String
         "NULL" ->keine Daten. */
         col_len = 4;
      /* maximale Länge von Spalten-Info verändern */
      field->max_length = col_len;
   }
   /* Namen der Tabelle ausgeben */
   printf("Daten der Tabelle: [ %s ]\n", field->table);
   print_line(res);
   printf("|");
   /* alles wieder auf den Anfang stellen */
   mysql_field_seek (res, 0);
   /* jetzt den Tabellenkopf ausgeben (titel, hauptrolle, fsk,
    * gedreht) */
   for (i = 0; i < mysql_num_fields (res); i++)  {
      field = mysql_fetch_field (res);
      printf (" %-*s |", field->max_length, field->name);
   }
   printf("\n");
   print_line(res);

   /* jetzt die Daten aus der Struktur MYSQL_RES zeilenweise
    * einlesen */
   while ((row = mysql_fetch_row (res)) != NULL) {
      mysql_field_seek (res, 0);
      printf("|");
      for (i = 0; i < mysql_num_fields (res); i++) {
         /* Spalte für Spalte abarbeiten */
         field = mysql_fetch_field (res);
         /* keine Daten in dieser Spalte */
         if (row[i] == NULL)
            printf (" %-*s |", field->max_length, "NULL");
         /* Handelt es sich um ein numerisches Feld? */
         else if (IS_NUM (field->type))
            /* Dann wird der Inhalt rechtsbündig formatiert
             * ausgegeben. */
            printf (" %*s |", field->max_length, row[i]);
         else
            /* Der Wert der Spalte ist ein String, also
             * linksbündige Ausgabe. */
            printf (" %-*s |", field->max_length, row[i]);
      }
      printf("\n");
   }
   print_line(res);
   mysql_free_result(res);
}
コード例 #30
0
//---------------------------------------------------------------------------
bool __fastcall TForm1::get_desc_table(String table_name)
{
 MYSQL_RES *res, *res1;
 MYSQL_ROW row;
 AnsiString use_db, show_cols, show_desc;
 unsigned int num_fields;
 int fields_control = 0, grid_row = 1, fields_number;
 b_new_line= true;

 clean_desc_grid();
 use_db = "use ";
 use_db+= DBView->Selected->Text.c_str();
 show_desc = "desc ";
 show_cols = "show full columns from ";
 show_cols+= table_name.c_str();
 show_desc+= table_name.c_str();

 if (mysql_query(MySQL, use_db.c_str() ))
  return false;

 if (mysql_query(MySQL, show_cols.c_str() ) ||
      !(res1=mysql_store_result(MySQL)))
 {
  if (mysql_query(MySQL, show_desc.c_str() ) ||
       !(res1=mysql_store_result(MySQL)))
   return false ;
 }
  mysql_fetch_row(res1);
  mysql_field_seek(res1,0);
  fields_number = (mysql_num_fields(res1) - 2);
  mysql_free_result(res1);

 if (mysql_query(MySQL, show_cols.c_str() ) ||
 !(res=mysql_store_result(MySQL)))
 {
  if (mysql_query(MySQL, show_desc.c_str() ) ||
      !(res=mysql_store_result(MySQL)))
   return false ;
 }
 titles_grid();
 while ((row=mysql_fetch_row(res)) != 0)
 {
   mysql_field_seek(res,0);
   for (num_fields=0 ; num_fields < mysql_num_fields(res); num_fields++)
   {
    if (fields_control <= fields_number )
    {
     desc_table_grid->Cells[fields_control][grid_row] = row[num_fields];
     fields_control++;
    }
    else
    {
     desc_table_grid->Cells[(fields_control)][grid_row] = row[num_fields];
     fields_control = 0;
     grid_row++ ;
     desc_table_grid->RowCount++;
    }
   }
 }
 desc_table_grid->RowCount--;
 mysql_free_result(res);
 return true;
}