--- loncom/interface/lonmysql.pm 2003/12/26 19:12:51 1.16 +++ loncom/interface/lonmysql.pm 2004/04/19 21:29:15 1.20 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # MySQL utility functions # -# $Id: lonmysql.pm,v 1.16 2003/12/26 19:12:51 www Exp $ +# $Id: lonmysql.pm,v 1.20 2004/04/19 21:29:15 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -559,7 +559,27 @@ sub update_table_info { $debugstring = "Retrieved table info for $tablename"; return 1; } +############################### + +=pod + +=item &col_order() + +Inputs: table id + +Returns: array with column order + +=cut + +sub col_order { + my $table_id=shift; + if (&update_table_info($table_id)) { + return @{$Tables{$table_id}->{'Col_order'}}; + } else { + return (); + } +} ############################### =pod @@ -694,7 +714,8 @@ sub create_table { ############################################# my $count = $dbh->do($request); if (! defined($count)) { - $errorstring = "$dbh ATTEMPTED:\n".$request."\nRESULTING ERROR:\n"; + $errorstring = "$dbh ATTEMPTED:\n".$request."\nRESULTING ERROR:\n". + $dbh->errstr(); return undef; } # @@ -912,18 +933,20 @@ sub tables_in_db { return undef if (!defined(&connect_to_db())); my $sth=$dbh->prepare('SHOW TABLES'); $sth->execute(); - if ($sth->err) { - $errorstring = "$dbh ATTEMPTED:\n".'SHOW TABLES'. + $sth->execute(); + my $aref = $sth->fetchall_arrayref; + if ($sth->err()) { + $errorstring = + "$dbh ATTEMPTED:\n".'fetchall_arrayref after SHOW TABLES'. "\nRESULTING ERROR:\n".$sth->errstr; return undef; } - my $aref = $sth->fetchall_arrayref; - my @table_list=(); + my @table_list; foreach (@$aref) { - push @table_list,$_->[0]; + push(@table_list,$_->[0]); } - $debugstring = "Got list of tables in DB: @table_list"; - return @table_list; + $debugstring = "Got list of tables in DB: ".join(',',@table_list); + return(@table_list); } ########################################### @@ -1002,11 +1025,10 @@ sub remove_from_table { return undef if (!defined(&connect_to_db())); # $table_id = &translate_id($table_id); - my $command = 'DELETE FROM '.$table_id.' WHERE '.$dbh->quote($column). + my $command = 'DELETE FROM '.$table_id.' WHERE '.$column. " LIKE BINARY ".$dbh->quote($value); my $sth = $dbh->prepare($command); - $sth->execute(); - if ($sth->err) { + unless ($sth->execute()) { $errorstring = "ERROR on execution of ".$command."\n".$sth->errstr; return undef; }