version 1.3, 2002/07/30 18:26:40
|
version 1.7, 2002/08/21 21:29:51
|
Line 327 sub connect_to_db {
|
Line 327 sub connect_to_db {
|
$Apache::lonnet::perlvar{'lonSqlAccess'}, |
$Apache::lonnet::perlvar{'lonSqlAccess'}, |
{ RaiseError=>0,PrintError=>0}))) { |
{ RaiseError=>0,PrintError=>0}))) { |
$debugstring = "Unable to connect to loncapa database."; |
$debugstring = "Unable to connect to loncapa database."; |
if ($dbh->err) { |
if (! defined($dbh)) { |
|
$debugstring = "Unable to connect to loncapa database."; |
|
$errorstring = "dbh was undefined."; |
|
} elsif ($dbh->err) { |
$errorstring = "Connection error: ".$dbh->errstr; |
$errorstring = "Connection error: ".$dbh->errstr; |
} |
} |
return undef; |
return undef; |
Line 481 sub update_table_info {
|
Line 484 sub update_table_info {
|
# Determine the column order |
# Determine the column order |
# |
# |
$db_command = "DESCRIBE $tablename"; |
$db_command = "DESCRIBE $tablename"; |
my $sth = $dbh->prepare($db_command); |
$sth = $dbh->prepare($db_command); |
$sth->execute(); |
$sth->execute(); |
if ($sth->err) { |
if ($sth->err) { |
$errorstring = "$dbh ATTEMPTED:\n".$db_command."\nRESULTING ERROR:\n". |
$errorstring = "$dbh ATTEMPTED:\n".$db_command."\nRESULTING ERROR:\n". |
Line 570 sub create_table {
|
Line 573 sub create_table {
|
# skip blank items. |
# skip blank items. |
push (@Columns,$col_des) if ($col_des ne ''); |
push (@Columns,$col_des) if ($col_des ne ''); |
} |
} |
if (exists($table_des->{'fulltext'})) { |
if (exists($table_des->{'fulltext'}) && (@{$table_des->{'fulltext'}})) { |
push (@Columns,'FULLTEXT ('.join(',',@{$table_des->{'fulltext'}}).')'); |
push (@Columns,'FULLTEXT ('.join(',',@{$table_des->{'fulltext'}}).')'); |
} |
} |
$request .= "(".join(", ",@Columns).") "; |
$request .= "(".join(", ",@Columns).") "; |
Line 609 Used internally to prevent table name co
|
Line 612 Used internally to prevent table name co
|
############################### |
############################### |
sub get_new_table_id { |
sub get_new_table_id { |
my $newid = 0; |
my $newid = 0; |
my $name_regex = '^'.$ENV{'user.name'}.'_'.$ENV{'user.domain'}."_(\d+)\$"; |
|
my @tables = &tables_in_db(); |
my @tables = &tables_in_db(); |
foreach (@tables) { |
foreach (@tables) { |
if (/^$ENV{'user.name'}_$ENV{'user.domain'}_(\d+)$/) { |
if (/^$ENV{'user.name'}_$ENV{'user.domain'}_(\d+)$/) { |
Line 657 sub get_rows {
|
Line 659 sub get_rows {
|
} |
} |
$debugstring = "Got rows matching $condition"; |
$debugstring = "Got rows matching $condition"; |
my @Results = @{$sth->fetchall_arrayref}; |
my @Results = @{$sth->fetchall_arrayref}; |
foreach my $row (@Results) { |
|
for(my $i=0;$i<@$row;$i++) { |
|
$row->[$i]=&Apache::lonnet::unescape($row->[$i]); |
|
} |
|
} |
|
return @Results; |
return @Results; |
} |
} |
|
|
Line 711 sub store_row {
|
Line 708 sub store_row {
|
@Parameters = @$rowdata; |
@Parameters = @$rowdata; |
} elsif (ref($rowdata) eq 'HASH') { |
} elsif (ref($rowdata) eq 'HASH') { |
foreach (@{$Tables{$tablename}->{'Col_order'}}) { |
foreach (@{$Tables{$tablename}->{'Col_order'}}) { |
push(@Parameters,&Apache::lonnet::escape($rowdata->{$_})); |
push(@Parameters,$rowdata->{$_}); |
} |
} |
} |
} |
$sth->execute(@Parameters); |
$sth->execute(@Parameters); |
Line 738 Returns undef on error.
|
Line 735 Returns undef on error.
|
########################################### |
########################################### |
sub tables_in_db { |
sub tables_in_db { |
return undef if (!defined(&connect_to_db())); |
return undef if (!defined(&connect_to_db())); |
my $sth=$dbh->prepare('SHOW TABLES;'); |
my $sth=$dbh->prepare('SHOW TABLES'); |
$sth->execute(); |
$sth->execute(); |
if ($sth->err) { |
if ($sth->err) { |
$errorstring = "$dbh ATTEMPTED:\n".'SHOW TABLES'. |
$errorstring = "$dbh ATTEMPTED:\n".'SHOW TABLES'. |
Line 808 sub check_table {
|
Line 805 sub check_table {
|
return $result; |
return $result; |
} |
} |
|
|
|
########################################### |
|
|
|
=pod |
|
|
|
=item &remove_from_table($table_id,$column,$value) |
|
|
|
Executes a "delete from $tableid where $column like binary '$value'". |
|
|
|
=cut |
|
|
|
########################################### |
|
sub remove_from_table { |
|
my ($table_id,$column,$value) = @_; |
|
return undef if (!defined(&connect_to_db())); |
|
# |
|
$table_id = &translate_id($table_id); |
|
my $command = 'DELETE FROM '.$table_id.' WHERE '.$dbh->quote($column). |
|
" LIKE BINARY ".$dbh->quote($value); |
|
my $sth = $dbh->prepare($command); |
|
$sth->execute(); |
|
if ($sth->err) { |
|
$errorstring = "ERROR on execution of ".$command."\n".$sth->errstr; |
|
return undef; |
|
} |
|
my $rows = $sth->rows; |
|
return $rows; |
|
} |
|
|
|
|
1; |
1; |
|
|
__END__; |
__END__; |
|
|
|
=pod |
|
|
|
=back |
|
|
|
=cut |