[LON-CAPA-cvs] cvs: loncom / lonsql /lonnet/perl lonnet.pm
raeburn
raeburn at source.lon-capa.org
Thu Nov 26 09:23:20 EST 2026
raeburn Thu Nov 26 14:23:20 2026 EDT
Modified files:
/loncom/lonnet/perl lonnet.pm
/loncom lonsql
Log:
- Parameterized queries
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1172.2.118.2.18 loncom/lonnet/perl/lonnet.pm:1.1172.2.118.2.19
--- loncom/lonnet/perl/lonnet.pm:1.1172.2.118.2.18 Wed Feb 10 15:48:14 2021
+++ loncom/lonnet/perl/lonnet.pm Thu Feb 11 20:25:43 2021
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.1172.2.118.2.18 2021/02/10 15:48:14 raeburn Exp $
+# $Id: lonnet.pm,v 1.1172.2.118.2.19 2021/02/11 20:25:43 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3785,6 +3785,10 @@
# Replace all .\d. sequences with _\d. so they no longer look like version
# numbers
$fname=~s/\.(\d+)(?=\.)/_$1/g;
+# Replace three or more adjacent underscores with one for consistency
+# with loncfile::filename_check() so complete url can be extracted by
+# lonnet::decode_symb()
+ $fname=~s/_{3,}/_/g;
return $fname;
}
Index: loncom/lonsql
diff -u loncom/lonsql:1.103 loncom/lonsql:1.104
--- loncom/lonsql:1.103 Thu Nov 26 14:03:57 2026
+++ loncom/lonsql Thu Nov 26 14:23:20 2026
@@ -3,7 +3,7 @@
# The LearningOnline Network
# lonsql - LON TCP-MySQL-Server Daemon for handling database requests.
#
-# $Id: lonsql,v 1.103 2026/11/26 14:03:57 raeburn Exp $
+# $Id: lonsql,v 1.104 2026/11/26 14:23:20 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -622,6 +622,7 @@
push(@fields,$coldata->{'name'});
}
my $fieldlist = join(',', at fields);
+ my @params;
$srchterm =~ s/([%_\\])/\\$1/g;
$query = "SELECT $fieldlist FROM allusers WHERE (domain = $quoted_dom AND ";
if ($srchby eq 'lastfirst') {
@@ -629,14 +630,15 @@
$fragfirst =~ s/^\s+//;
$fraglast =~ s/\s+$//;
if ($srchtype eq 'exact') {
- $query .= 'lastname = '.$dbh->quote($fraglast).
- ' AND firstname = '.$dbh->quote($fragfirst);
- } elsif ($srchtype eq 'begins') {
- $query .= 'lastname LIKE '.$dbh->quote($fraglast.'%').
- ' AND firstname LIKE '.$dbh->quote($fragfirst.'%');
+ $query .= 'lastname = ? AND firstname = ?';
+ @params = ($fraglast,$fragfirst);
} else {
- $query .= 'lastname LIKE '.$dbh->quote('%'.$fraglast.'%').
- ' AND firstname LIKE '.$dbh->quote('%'.$fragfirst.'%');
+ $query .= 'lastname LIKE ? AND firstname LIKE ?';
+ if ($srchtype eq 'begins') {
+ @params = ($fraglast.'%',$fragfirst.'%');
+ } else {
+ @params = ('%'.$fraglast.'%','%'.$fragfirst.'%');
+ }
}
} else {
my %srchfield = (
@@ -647,11 +649,15 @@
);
if (exists($srchfield{$srchby})) {
if ($srchtype eq 'exact') {
- $query .= $srchfield{$srchby}.' = '.$dbh->quote($srchterm);
- } elsif ($srchtype eq 'begins') {
- $query .= $srchfield{$srchby}.' LIKE '.$dbh->quote($srchterm.'%');
+ $query .= $srchfield{$srchby}.' = ?';
+ @params = ($srchterm);
} else {
- $query .= $srchfield{$srchby}.' LIKE '.$dbh->quote('%'.$srchterm.'%');
+ $query .= $srchfield{$srchby}.' LIKE ?';
+ if ($srchtype eq 'begins') {
+ @params = ($srchterm.'%');
+ } else {
+ @params = ('%'.$srchterm.'%');
+ }
}
} else {
&logthis('<font color="blue">'.
@@ -661,7 +667,7 @@
}
$query .= ") ORDER BY username ";
my $sth = $dbh->prepare($query);
- if ($sth->execute()) {
+ if ($sth->execute(@params)) {
my @results;
while (my @row = $sth->fetchrow_array) {
my @items;
More information about the LON-CAPA-cvs
mailing list