Re: why doesn't this work? (C code)

2001-04-22 Thread Sinisa Milivojevic

Peter Faulks writes:
> On Sat, 21 Apr 2001 14:12:20 +0300 (EEST), Sinisa Milivojevic wrote:
> 
> >As our manual clearly describes one connection can be used for one
> >query at a time, unless you use threads and mutexes.
> 
> G'day
> 
> As I said, it worked fine b4 and I got it to work again. I _assumed_
> the reason it fell over was because of an unneccessary call to
> mysql_free_result().
> 
> Without actually having looked at MySql's source code, would it be
> logical to assume that a call to mysql_store_result() would free the
> 'cursor' resources as it's last act, and mysql_free_result() simply
> frees the 2D char array result set? If so, then I can't see where the
> problem would be 
> 
> This is a worry - I use this method (inner and outer cursors) all the
> time. (I come from using Sybase / embedded SQL - where you can declare
> cursors and use host variables)
> 
> I'm only really using MySql because that's what most ISP's seem to
> provide. If this issue is going to cause me grief, I might have to find
> an ISP who provides Postgres...:-)
> 
> Regards
> 
> 

Hi!

mysql_store_result does not free any memory. 

Memory is freed by mysql_free_result only. 

If you wish to have multiple cursors, you should try to use local
variables only.

That is especially very easy and flexible with MySQL++. 


Regards,

Sinisa

    __ _   _  ___ ==  MySQL AB
 /*/\*\/\*\   /*/ \*\ /*/ \*\ |*| Sinisa Milivojevic
/*/ /*/ /*/   \*\_   |*|   |*||*| mailto:[EMAIL PROTECTED]
   /*/ /*/ /*/\*\/*/  \*\|*|   |*||*| Larnaca, Cyprus
  /*/ /*/  /*/\*\_/*/ \*\_/*/ |*|
  /*/^^^\*\^^^
 /*/ \*\Developers Team

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: why doesn't this work? (C code)

2001-04-21 Thread Peter Faulks

On Sat, 21 Apr 2001 14:12:20 +0300 (EEST), Sinisa Milivojevic wrote:

>As our manual clearly describes one connection can be used for one
>query at a time, unless you use threads and mutexes.

G'day

As I said, it worked fine b4 and I got it to work again. I _assumed_
the reason it fell over was because of an unneccessary call to
mysql_free_result().

Without actually having looked at MySql's source code, would it be
logical to assume that a call to mysql_store_result() would free the
'cursor' resources as it's last act, and mysql_free_result() simply
frees the 2D char array result set? If so, then I can't see where the
problem would be 

This is a worry - I use this method (inner and outer cursors) all the
time. (I come from using Sybase / embedded SQL - where you can declare
cursors and use host variables)

I'm only really using MySql because that's what most ISP's seem to
provide. If this issue is going to cause me grief, I might have to find
an ISP who provides Postgres...:-)

Regards


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: why doesn't this work? (C code)

2001-04-21 Thread Sinisa Milivojevic


Hi!

As our manual clearly describes one connection can be used for one
query at a time, unless you use threads and mutexes.


Regards,

Sinisa

    __ _   _  ___ ==  MySQL AB
 /*/\*\/\*\   /*/ \*\ /*/ \*\ |*| Sinisa Milivojevic
/*/ /*/ /*/   \*\_   |*|   |*||*| mailto:[EMAIL PROTECTED]
   /*/ /*/ /*/\*\/*/  \*\|*|   |*||*| Larnaca, Cyprus
  /*/ /*/  /*/\*\_/*/ \*\_/*/ |*|
  /*/^^^\*\^^^
 /*/ \*\Developers Team

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: why doesn't this work? (C code) - fixed (I hope)

2001-04-20 Thread Peter Faulks

I wrote:

>This USED to work, then all of a sudden for no apparent reason it has suddenly 
>decided not to: 

Notwithstanding it used to work, it would _appear_ that calling mysql_free_result() 
willy-nilly was the cause:

mysql_query(&mysql, theSql);
res1 = mysql_store_result(&mysql); 
if(res1)
{
  while((row1 = mysql_fetch_row(res1)))
  {
printf(theHtml1, row1[4]);
if(*row1[2] == 'l')
{
  sprintf(theSql, 
  "SELECT so_val, so_text FROM slct_optns WHERE otype_id = %s"
  " AND so_val > 0 ORDER BY so_val", row1[1]);
  mysql_query(&mysql, theSql);
  res2 = mysql_store_result(&mysql);
  if(res2)
  {
printf("", row1[5]);
while((row2 = mysql_fetch_row(res2)))
  printf("\n%s", row2[0], row2[1]);
printf("");
mysql_free_result(res2);
  }
}
else if(*row1[2] == 'e')
{
  printf(" %s ", 
row1[3], row1[5], row1[8]); 
}
printf("\n");
  }
  mysql_free_result(res1);
}

seems to fix the problem..

Regards





-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




why doesn't this work? (C code)

2001-04-20 Thread Peter Faulks

G'day,

This USED to work, then all of a sudden for no apparent reason it has suddenly decided 
not to: 

if I change the code thus:

if(*row1[2] == 'l')
{
   ;
}
else if(*row1[2] == 'e')
  etc.

the cgi programme completes, so I don't think the problem is elsewhere.

Is there something fundamentally wrong with using the same connection for more than 
one 'cursor'? I understood that mysql_store_result() simply writes the result set to a 
2D character array. T4 there shouldn't be a problem.


Any help much appreciated


-
static MYSQL_RES *res1, *res2;
static MYSQL mysql;
static MYSQL_ROW row1, row2;
static char theSql[250];

static void slct_opt(void)
{
  char theHtml1[] =
  "\n\n %s"
  "\n ";
  
  sprintf(theSql, 
  "SELECT oc.id, ot.id, oc.i_type, oc.i_prefix, oc.cls_txt, oc.o_name,"
  " ot.o_type, oc.i_len FROM optn_cls oc, optn_type ot"
  " WHERE oc.id = ot.ocls_id AND ot.type_id = %s"
  " GROUP BY ot.ocls_id ORDER BY ot.disp_ord", lstg_type);
  
  mysql_query(&mysql, theSql);
  res1 = mysql_store_result(&mysql); 
  if(res1)
  {
while((row1 = mysql_fetch_row(res1)))
{
  printf(theHtml1, row1[4]);
  if(*row1[2] == 'l')
  {
sprintf(theSql, 
"SELECT so_val, so_text FROM slct_optns WHERE otype_id = %s"
" AND so_val > 0 ORDER BY so_val", row1[1]);
mysql_query(&mysql, theSql);
res2 = mysql_store_result(&mysql);
if(res2)
{
  printf("",  row1[5]);
  while((row2 = mysql_fetch_row(res2)))
printf("\n%s", row2[0], row2[1]);
  printf("");
}
mysql_free_result(res2);
  }
  else if(*row1[2] == 'e')
  {
printf(" %s ", 
   row1[3], row1[5],row1[8]); 
  }
}
printf("\n");
  }
  mysql_free_result(res1);
  mysql_free_result(res2);
}



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




why doesn't this work? (C code)

2001-04-20 Thread Peter Faulks

G'day,

This USED to work, then all of a sudden for no apparent reason it has
suddenly decided not to: 
if I change the code thus:

if(*row1[2] == 'l')
{
   ;
}
else if(*row1[2] == 'e')

It completes, but of course this isn't any good.

Is there something fundamentally wrong with using the same connection
for more than one 'cursor'? I understood that mysq_store_result()
simply writes the result set to a 2D character array. T4 there
should'nt be a problem.

-
static MYSQL_RES *res1, *res2;
static MYSQL mysql;
static MYSQL_ROW row1, row2;
static char theSql[250];

static void slct_opt(void)
{
char theHtml1[] =
"\n\n %s"
"\n ";

sprintf(theSql, 
"SELECT oc.id, ot.id, oc.i_type, oc.i_prefix, oc.cls_txt,
oc.o_name,"
" ot.o_type, oc.i_len FROM optn_cls oc, optn_type ot"
" WHERE oc.id = ot.ocls_id AND ot.type_id = %s"
" GROUP BY ot.ocls_id ORDER BY ot.disp_ord", lstg_type);

mysql_query(&mysql, theSql);
res1 = mysql_store_result(&mysql); 
if(res1)
{
while((row1 = mysql_fetch_row(res1)))
{
printf(theHtml1, row1[4]);
if(*row1[2] == 'l')
{
sprintf(theSql, 
"SELECT so_val, so_text FROM slct_optns
WHERE otype_id = %s"
" AND so_val > 0 ORDER BY so_val",
row1[1]);
mysql_query(&mysql, theSql);
res2 = mysql_store_result(&mysql);
if(res2)
{
printf("",
row1[5]);
while((row2 =
mysql_fetch_row(res2)))
printf("\n%s", row2[0], row2[1]);
printf("");
}
mysql_free_result(res2);
}
else if(*row1[2] == 'e')
{
printf(" %s ", row1[3], row1[5],
row1[8]); 
}
}
printf("\n");
}
mysql_free_result(res1);
mysql_free_result(res2);
}

Any help much appreciated


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php