Hi!
>>>>> "Alexander" == Alexander Barkov <bar@stripped> writes:
Alexander> Hello!
Alexander> I need to access to mysql result in C program in this style.
Alexander> value=mysql_value(res,i,j),
Alexander> where "i" is row number and "j" is column number.
Alexander> It is required for unified code for many different
Alexander> databases.
Alexander> Surely, there is a chance to write something like this:
Alexander> mysql_data_seek(res,i);
Alexander> row=mysql_fetch_row(res);
Alexander> value=row[j];
Alexander> But mysql_data_seek seems to work very slow, especially
Alexander> with 10000, 20000 or above rows in result.
Alexander> Is there any better solution?
Alexander> Any help would be appreciated.
Alexander> Thanks.
The problem is that mysql_data_seek() searches sequentially after the
data.
What interface are you using to the other databases; I haven't heard
of anyone supporting a similar interface as the above.
On the other hand, you can quite easily create on for MySQL yourself
using mysql_row_seek(), which is very fast.
Something like:
MYSQL_ROW_OFFSET *values=mysql_init_values(mysql_result);
....
value=mysql_value(mysql_result,values,i,j);
.....
free((char*) values);
and the functions would look something like (note this isn't tested,
but as you are a C programmer, this shouldn't be a problem :)
MYSQL_ROW_OFFSET* mysql_init_values(MYSQL_RES *mysql_result)
{
unsigned long long rows=mysql_num_rows(mysql_result),i;
MYSQL_ROW_OFFSET *values=malloc(rows *sizeof(MYSQL_ROW_OFFSET));
if (!values)
return 0; /* Error: Probably out of memory * /
for (i=0 ; i < rows ; i++)
{
values[0]=mysql_row_tell(mysql_result);
if (mysql_fetch_row(mysql_result))
{ /* Should never happen, but ... */
free((char*) values);
return 0;
}
}
return values;
}
char *mysql_value(MYSQL_RES* mysql_result, MYSQL_ROW_OFFSET *values,
usigned int row, unsigned int column)
{
/* No error checking ..; We trust the caller. */
mysql_row_seek(mysql_result,values[row]);
return mysql_fetch_row(mysql_result)[column];
}
Regards,
Monty
| Thread |
|---|
| • mysql_value(res,i,j) wanted :-) | (Alexander Barkov) | 28 Jan |
| • Re: mysql_value(res,i,j) wanted :-) | sinisa | 28 Jan |
| • ANSWER: mysql_value(res,i,j) wanted :-) | Michael Widenius | 29 Jan |
| • Re: ANSWER: mysql_value(res,i,j) wanted :-) | Benjamin Pflugmann | 30 Jan |
| • Re: ANSWER: mysql_value(res,i,j) wanted :-) | Michael Widenius | 30 Jan |
| • Re: ANSWER: mysql_value(res,i,j) wanted :-) | Benjamin Pflugmann | 30 Jan |
| • Re: ANSWER: mysql_value(res,i,j) wanted :-) | Michael Widenius | 5 Feb |
| • dump error | kevin | 7 Feb |
| • Re: dump error | sinisa | 7 Feb |
| • DATE arithmatic | KevinWaterson | 21 Feb |
| • Re: DATE arithmatic | sinisa | 21 Feb |
| • Re: DATE arithmatic | Vivek Khera | 21 Feb |
| • triggers ? | KevinWaterson | 12 Mar |
| • Re: triggers ? | Jonathan Stimmel | 12 Mar |