can't flush buffers?
I posted something like this a week ago, but typos in my message kept anyone from understanding the issue. I am trying to return each row to the client as it comes from the database, instead of waiting for all the rows to be returned before displaying them. I have set $|=1 and added $r->flush; after every print statement ( I realize this is redundant ) but to no avail. This is the relevant code: while ($sth->fetch) { $r->print ("", map("$_",@cols), ""); $r->rflush; } Here is the complete package: package Sql::Client; use Apache::Request; use strict; use warnings; use Apache::Constants qw(:common); my $r; #request my $apr; #Apache::Request my $host; #hostname of remote user my $sql;#sql to execute $|=1; sub getarray ($) { my $dbh; # Database handle my $sth;# Statement handle my $p_sql; # sql statement passed as parameter my @cols; #column array to bind results my $titles; # array ref to column headers $p_sql = shift; # Connect $dbh = DBI->connect ( "DBI:mysql:links_db::localhost", "nobody", "somebody", { PrintError => 1,# warn() on errors RaiseError => 0, # don't die on error AutoCommit => 1,# commit executes immediately } ); # prepare statment $sth = $dbh->prepare($p_sql); $sth->execute; $titles = $sth->{NAME_uc}; #-- # for minimal memory use, do it this way @cols[0..$#$titles] = (); $sth->bind_columns(\(@cols)); $r->print( ""); $r->print ("", map("$_",@$titles), ""); while ($sth->fetch) { $r->print ("", map("$_",@cols), ""); $r->rflush; } $r->print (""); return; } sub handler { $r = shift; $apr = Apache::Request->new($r); $sql = $apr->param('sql') || 'SELECT'; $sql='SELECT' if $apr->param('reset'); $r->content_type( 'text/html' ); $r->send_http_header; return OK if $r->header_only; $host = $r->get_remote_host; $r->print(< Hello $host Sql Client Enter your Select Statement: $sql HTMLEND $r->rflush; getarray($sql) unless $sql =~ /^SELECT$/; $r->print(< HTMLEND return OK; } 1;
Re: can't flush buffer?
oops, typos in my message. In fact, I have done just as you suggest, but it doesn't work. Thanks, ~quagly
Re: can't flush buffer?
Yes, I have read all of that. That is what I am following. It just doesn't work. ~quagly
can't flush buffer?
As a test of my new mod_perl abilities I wrote a trivial SQL client. It works, but if the query returns many rows then it takes a while. As a first step I thought I would call $r->rflush; with every row printed but this does not work. I also tried $|=0; with no effect. Here is the full module, 100 lines. The rows are printed in getarray ($$) Any ideas would be appreciated ~quagly package Sql::Client; use Apache::Request; use strict; use warnings; use Apache::Constants qw(:common); my $r; #request my $apr; #Apache::Request my $host; #hostname of remote user my $sql;#sql to execute sub getarray ($$) { my $dbh; # Database handle my $sth;# Statement handle my $p_sql; # sql statement passed as parameter my @cols; #column array to bind results my $titles; # array ref to column headers my $r; # maybe if I pass the request it will work $p_sql = shift; $r = shift; # Connect $dbh = DBI->connect ( "DBI:mysql:links_db::localhost", "nobody", "somebody", { PrintError => 1,# warn() on errors RaiseError => 0, # don't die on error AutoCommit => 1,# commit executes immediately } ); # prepare statment $sth = $dbh->prepare($p_sql); $sth->execute; $titles = $sth->{NAME_uc}; #-- # for minimal memory use, do it this way @cols[0..$#$titles] = (); $sth->bind_columns(\(@cols)); print ""; print "", map("$_",@$titles), ""; while ($sth->fetch) { print "", map("$_",@cols), $r->rflush; } print ""; return; } sub handler { $r = shift; $apr = Apache::Request->new($r); $sql = $apr->param('sql') || 'SELECT'; $sql='SELECT' if $apr->param('reset'); $r->content_type( 'text/html' ); $r->send_http_header; return OK if $r->header_only; $host = $r->get_remote_host; $r->print(< Hello $host Sql Client Enter your Select Statement: $sql HTMLEND getarray($sql,$r) unless $sql =~ /^SELECT$/; $r->print(< HTMLEND return OK; } 1; ~ "";
Should I use CGI.pm?
I am working my way through the eagle book. I have not used CGI.pm before. It is used in many (most?) of the examples. Is it worth learning to use it? I am not clear whether the authors are using it because the think it is the best way to go, or because they already know it ( or created it )and it is convenient. I have not done CGI programming before, but have some experience with java servlets. It there a compelling reason I should learn it ( other than that it would help me to understand the book? ) Thanks, ~quagly - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: learning for someone like me
This book looks great! I had seen it before, but assumed that it was all C. Thanks for the tip. ~quagly - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
learning for someone like me
I am looking for a source of learning, books, sites, whatever. I am a unix/oracle developer. I am experienced in perl/DBI. I thought it would be interesting to learn something about web development. I have some experience with HTML, XML-XSLT and Java Servlets, but Java is not fun. So I am looking for information on creating dynamic database driven web sites using perl. Most of the introductory web development books/sites do little with databases, and even pride themselves on showing how much you can do without knowing much about the backend. Books that look at building dynamic sites in depth assume you have a strong grounding in CGI/HTML. Ideas? ~quagly - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]