--- wakaba_orig.pl 2008-02-11 00:53:14.000000000 -0500 +++ wakaba.pl 2008-02-11 01:28:10.000000000 -0500 @@ -551,7 +551,9 @@ my ($filename,$md5,$width,$height,$thumbnail,$tn_width,$tn_height)=process_file($file,$uploadname,$time) if($file); # finally, write to the database - my $sth=$dbh->prepare("INSERT INTO ".SQL_TABLE." VALUES(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);") or make_error(S_SQLFAIL); + my $sth=$dbh->prepare("INSERT INTO ".SQL_TABLE + ." (parent,timestamp,lasthit,ip,date,name,trip,email,subject,password,comment,image,size,md5,width,height,thumbnail,tn_width,tn_height)" + ." VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);") or make_error(S_SQLFAIL); $sth->execute($parent,$time,$lasthit,$numip, $date,$name,$trip,$email,$subject,$password,$comment, $filename,$size,$md5,$width,$height,$thumbnail,$tn_width,$tn_height) or make_error(S_SQLFAIL); @@ -717,7 +719,9 @@ else { # unknown IP, check for proxy my $command = PROXY_COMMAND . " " . $ip; - $sth=$dbh->prepare("INSERT INTO ".SQL_PROXY_TABLE." VALUES(null,?,?,?,?);") or make_error(S_SQLFAIL); + $sth=$dbh->prepare("INSERT INTO ".SQL_PROXY_TABLE + ." (type, ip, timestamp, date)" + ." VALUES(?,?,?,?);") or make_error(S_SQLFAIL); if(`$command`) { @@ -755,7 +759,9 @@ $sth->execute($ip) or make_error(S_SQLFAIL); # Add requested entry - $sth=$dbh->prepare("INSERT INTO ".SQL_PROXY_TABLE." VALUES(null,?,?,?,?);") or make_error(S_SQLFAIL); + $sth=$dbh->prepare("INSERT INTO ".SQL_PROXY_TABLE + ." (type, ip, timestamp, date)" + ." VALUES(?,?,?,?);") or make_error(S_SQLFAIL); $sth->execute($type,$ip,$timestamp,$date) or make_error(S_SQLFAIL); make_http_forward(get_script_name()."?admin=$admin&task=proxy",ALTERNATE_REDIRECT); @@ -1446,7 +1452,9 @@ $comment=clean_string(decode_string($comment,CHARSET)); - $sth=$dbh->prepare("INSERT INTO ".SQL_ADMIN_TABLE." VALUES(null,?,?,?,?,?);") or make_error(S_SQLFAIL); + $sth=$dbh->prepare("INSERT INTO ".SQL_ADMIN_TABLE + ." (type, comment, ival1, ival2, sval1)" + ." VALUES(?,?,?,?,?);") or make_error(S_SQLFAIL); $sth->execute($type,$comment,$ival1,$ival2,$sval1) or make_error(S_SQLFAIL); make_http_forward(get_script_name()."?admin=$admin&task=bans",ALTERNATE_REDIRECT); @@ -1472,8 +1480,8 @@ check_password($admin,ADMIN_PASS); - $sth=$dbh->prepare("SELECT num FROM ".SQL_TABLE." WHERE ip & ? = ? & ?;") or make_error(S_SQLFAIL); - $sth->execute($mask,$ip,$mask) or make_error(S_SQLFAIL); + $sth=$dbh->prepare("SELECT num FROM ".SQL_TABLE." WHERE ip & ? = ?;") or make_error(S_SQLFAIL); + $sth->execute($mask,$ip & $mask) or make_error(S_SQLFAIL); while($row=$sth->fetchrow_hashref()) { push(@posts,$$row{num}); } delete_stuff('',0,0,$admin,@posts); @@ -1654,7 +1662,7 @@ "parent INTEGER,". # Parent post for replies in threads. For original posts, must be set to 0 (and not null) "timestamp INTEGER,". # Timestamp in seconds for when the post was created "lasthit INTEGER,". # Last activity in thread. Must be set to the same value for BOTH the original post and all replies! - "ip TEXT,". # IP number of poster, in integer form! + "ip BIGINT,". # IP number of poster, in integer form! "date TEXT,". # The date, as a string "name TEXT,". # Name of the poster @@ -1687,8 +1695,14 @@ "num ".get_sql_autoincrement().",". # Entry number, auto-increments "type TEXT,". # Type of entry (ipban, wordban, etc) "comment TEXT,". # Comment for the entry - "ival1 TEXT,". # Integer value 1 (usually IP) - "ival2 TEXT,". # Integer value 2 (usually netmask) + # with mysql/sqlite we could probably get away with 'unsigned integer' + # but postgres doesn't do unsigned. it does have a 'cidr' type which + # even does netmasks and stuff, but if we're to maintain compatibility + # we can't use it. also postgres refuses to do bit math on a string + # value (which makes lots of sense ;) so the lowest common denominator + # here is 'bigint'... + "ival1 BIGINT,". # Integer value 1 (usually IP) + "ival2 BIGINT,". # Integer value 2 (usually netmask) "sval1 TEXT". # String value 1 ");") or make_error(S_SQLFAIL); @@ -1704,7 +1718,7 @@ "num ".get_sql_autoincrement().",". # Entry number, auto-increments "type TEXT,". # Type of entry (black, white, etc) - "ip TEXT,". # IP address + "ip BIGINT,". # IP address "timestamp INTEGER,". # Age since epoch "date TEXT". # Human-readable form of date @@ -1736,6 +1750,7 @@ return 'INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT' if(SQL_DBI_SOURCE=~/^DBI:mysql:/i); return 'INTEGER PRIMARY KEY' if(SQL_DBI_SOURCE=~/^DBI:SQLite:/i); return 'INTEGER PRIMARY KEY' if(SQL_DBI_SOURCE=~/^DBI:SQLite2:/i); + return 'SERIAL PRIMARY KEY' if(SQL_DBI_SOURCE=~/DBI:Pg:/i); make_error(S_SQLCONF); # maybe there should be a sane default case instead? }