#!perl use CGI ; use DBIx::Recordset ; $DBIx::Recordset::Debug = 0 ; $q = new CGI ; print $q -> header ; print $q -> start_html (title=>'Example for DBIx::Recordset') ; print '
Available DBD drivers \n" ; print $q -> scrolling_list (-name=>"driver", -values=>\@drvs, -size=>7) ; print " | \n" ;
print "First of all you have to specify which database and table you want to access and enter\n" ;
print "the user and password (if required) For the Datasource you have the following Options: | \n" ;
print "
Datasource: | \n" ; print "\n" ; # fixup for drivers which does not support the data_sources method @dsns = () if ($dsns[0] =~ /HASH/ ) ; # fixup for mSQL/mysql driver for ($i = 0; $i <= $#dsns; $i++) { $dsns[$i] =~ s/^DBI/dbi/ ; } if ($#dsns >= 0) { print $q -> popup_menu (-name=>"!DataSource", -size=>"1", -value=>\@dsns) ; } else { print $q -> textfield (-name=>"!DataSource", -size=>20) ; print "Datasource list not available, enter DSN manual" ; } print " | \n" ; print "
Table: | \n" ; print "" , $q -> textfield (-name=>"!Table", -size=>"20"), " | \n" ; print "
User: | \n" ; print "" , $q -> textfield (-name=>"!Username", -size=>"20"), " | \n" ; print "
Password: | \n" ; print "" , $q -> password_field (-name=>"!Password", -size=>"20"), " | \n" ; print "
Rows Per Page: | \n" ; $q -> param (-name=>'$max', -value=>5) if (!$fdat{'$max'}) ; print "" , $q -> textfield (-name=>'$max', -size=>5), " | \n" ; print "
\n" ; print $q -> submit (-value=>"Show Datasources", -name=>"showdsn") ; print $q -> submit (-value=>"Show whole table", -name=>"show") ; print $q -> submit (-value=>"Specify condition", -name=>"cond") ; print $q -> reset (-name=>"Reset") ; print $q -> endform ; } elsif (defined ($fdat{'cond'})) { #### enter a search condition ##### delete $fdat{'cond'}; ### setup recordset ### $set = DBIx::Recordset -> SetupObject (\%fdat) ; ### get the names of all fields ### $names = $set -> AllNames () if ($set) ; print "
Datasource: | \n" ; print "\n" ; print $fdat{"!DataSource"} ; print " | \n" ; print "
Table: | \n" ; print "$fdat{'!Table'} | \n" ; print "
User: | \n" ; print "$fdat{'!Username'} | \n" ; print "
Rows Per Page: | \n" ; print "$fdat{'$max'} | \n" ; print "
ERROR: | \n" ; print "" , $DBI::errstr , " | \n" ; print "
\n" ; if ($set) { print $q -> startform (-method => GET) ; print "
Fieldname | \n" ; print "Operator | \n" ; print "Value | \n" ; print "
---|---|---|
$n | \n" ; print "", $q -> textfield (-name=>"\*$n", -size=>5), " | \n" ; print "", $q -> textfield (-name=>$n, -size=>20), " | \n" ; print "
\n" ; print $q -> hidden (-name=>'!DataSource', -value=>$fdat{'!DataSource'}) ; print $q -> hidden (-name=>'!Table', -value=>$fdat{'!Table'}) ; print $q -> hidden (-name=>'!Username', -value=>$fdat{'!Username'}) ; print $q -> hidden (-name=>'!Password', -value=>$fdat{'!Password'}) ; print $q -> hidden (-name=>'$max', -value=>$fdat{'$max'}) ; print $q -> hidden (-name=>'driver', -value=>$fdat{'driver'}) ; print $q -> submit (-value=>"Start search", -name=>"search") ; print $q -> submit (-value=>"Change Datasource", -name=>"showdsn") ; print $q -> reset (-name=>"Reset") ; print $q -> endform ; } } else { #### show query result #### ### setup object and do the query ### *set = DBIx::Recordset -> Search (\%fdat) ; ### get fieldnames of query ### $names = $set -> Names if ($set) ; print "
Datasource: | \n" ; print "\n" ; print $fdat{"!DataSource"} ; print " | \n" ; print "
Table: | \n" ; print "$fdat{'!Table'} | \n" ; print "
User: | \n" ; print "$fdat{'!Username'} | \n" ; print "
Rows Per Page: | \n" ; print "$fdat{'$max'} | \n" ; print "
ERROR: | \n" ; print "" , $DBI::errstr , " | \n" ; print "
Current Start Row: | \n" ; print "" , $set -> StartRecordNo , " | \n" ; print "
SQL Statement: | \n" ; print "" , $set -> LastSQLStatement , " | \n" ; print "
\n" ; print "
$n | \n" ; } print "
---|
$$r{lc($n)} | \n" ; } print "
\n" ; print $q ->submit (-value=>"Refresh", -name=>"refresh") ; print $q -> submit (-value=>"Specify condition", -name=>"cond") ; print $q -> submit (-value=>"Change Datasource", -name=>"showdsn") ; print $q -> endform ; } } ### cleanup ### DBIx::Recordset::Undef ('set') ; print $q -> end_html ;