function vertebrer_cell($fields) { $res = ""; foreach ($fields as $n => $t) { $texte = "#CHAMP_SQL{" . $n . "}"; if (preg_match('/\\s+references\\s+([\\w_]+)/', $t, $r)) { $url = "[(#SELF|parametre_url{page,'" . $r[1] . "'})]"; $texte = "<a href='{$url}'>" . $texte . "</a>"; } if (sql_test_int($t)) { $s = " style='text-align: right;'"; } else { $s = ''; if (sql_test_date($t)) { $texte = "[({$texte}|affdate_heure)]"; } } $res .= "\n\t\t<td{$s}>{$texte}</td>"; } return $res; }
/** * Renvoie les bons echappements (mais pas sur les fonctions comme NOW()) * * @param string|number $v Texte ou nombre à échapper * @param string $type Type de donnée attendue, description SQL de la colonne de destination * @return string|number Texte ou nombre échappé */ function _sqlite_calculer_cite($v, $type) { if ($type) { if (is_null($v) and stripos($type, "NOT NULL") === false) { return 'NULL'; } // null php se traduit en NULL SQL if (sql_test_date($type) and preg_match('/^\\w+\\(/', $v)) { return $v; } if (sql_test_int($type)) { if (is_numeric($v)) { return $v; } elseif (ctype_xdigit(substr($v, 2)) and strncmp($v, '0x', 2) == 0) { return hexdec(substr($v, 2)); } else { return intval($v); } } } else { // si on ne connait pas le type on le deduit de $v autant que possible if (is_numeric($v)) { return strval($v); } } if (function_exists('sqlite_escape_string')) { return "'" . sqlite_escape_string($v) . "'"; } // trouver un link sqlite3 pour faire l'echappement foreach ($GLOBALS['connexions'] as $s) { if (_sqlite_is_version(3, $l = $s['link'])) { return $l->quote($v); } } // echapper les ' en '' spip_log("Pas de methode sqlite_escape_string ni ->quote pour echapper", "sqlite." . _LOG_INFO_IMPORTANTE); return "'" . str_replace("'", "''", $v) . "'"; }
/** * Renvoie les bons echappements (mais pas sur les fonctions comme NOW()) * * @param string|number $v Texte ou nombre à échapper * @param string $type Type de donnée attendue, description SQL de la colonne de destination * @return string|number Texte ou nombre échappé */ function spip_mysql_cite($v, $type) { if (is_null($v) and stripos($type, "NOT NULL") === false) { return 'NULL'; } // null php se traduit en NULL SQL if (sql_test_date($type) and preg_match('/^\\w+\\(/', $v)) { return $v; } if (sql_test_int($type)) { if (is_numeric($v) or ctype_xdigit(substr($v, 2)) and $v[0] == '0' and $v[1] == 'x') { return $v; } else { return intval($v); } } return "'" . addslashes($v) . "'"; }
function spip_pg_cite($v, $t) { if (is_null($v)) { return 'NULL'; } // null php se traduit en NULL SQL if (sql_test_date($t)) { if ($v and strpos("0123456789", $v[0]) === false) { return spip_pg_frommysql($v); } else { if (strncmp($v, '0000', 4) == 0) { $v = "0001" . substr($v, 4); } if (strpos($v, "-00-00") === 4) { $v = substr($v, 0, 4) . "-01-01" . substr($v, 10); } return "timestamp '{$v}'"; } } elseif (!sql_test_int($t)) { return "'" . pg_escape_string($v) . "'"; } elseif (is_numeric($v) or strpos($v, 'CAST(') === 0) { return $v; } elseif ($v[0] == '0' and $v[1] !== 'x' and ctype_xdigit(substr($v, 1))) { return substr($v, 1); } else { spip_log("Warning: '{$v}' n'est pas de type {$t}", 'pg.' . _LOG_AVERTISSEMENT); return intval($v); } }
function spip_mysql_cite($v, $type) { if (sql_test_date($type) AND preg_match('/^\w+\(/', $v) OR (sql_test_int($type) AND (is_numeric($v) OR (ctype_xdigit(substr($v,2)) AND $v[0]=='0' AND $v[1]=='x')))) return $v; else return ("'" . addslashes($v) . "'"); }
function vertebrer_cell($fields) { $res = ""; foreach($fields as $n => $t) { $texte = "#" . strtoupper($n); if (preg_match('/\s+references\s+([\w_]+)/' , $t, $r)) { $url = "[(#SELF|parametre_url{page,'" . $r[1] . "'})]"; $texte = "<a href='$url'>" . $texte . "</a>"; } if (sql_test_int($t)) $s = " style='text-align: right;'"; else { $s = ''; if (sql_test_date($t)) $texte = "[($texte|affdate_heure)]"; } $res .= "\n\t\t<td$s>$texte</td>"; } return $res; }
function spip_pg_cite($v, $t) { if (sql_test_date($t)) { if ($v AND (strpos("0123456789", $v[0]) === false)) return spip_pg_frommysql($v); else { if (strpos($v, "-00-00") <= 4) { $annee = substr($v,0,4); if (!intval($annee)) $annee = '0001'; $v = $annee ."-01-01".substr($v,10); } return "timestamp '$v'"; } } elseif (!sql_test_int($t)) return ("'" . addslashes($v) . "'"); elseif (is_numeric($v) OR (strpos($v, 'CAST(') === 0)) return $v; elseif ($v[0]== '0' AND $v[1]!=='x' AND ctype_xdigit(substr($v,1))) return substr($v,1); else { spip_log("Warning: '$v' n'est pas de type $t", 'pg'); return intval($v); } }
function _sqlite_calculer_cite($v, $type) { if (sql_test_date($type) AND preg_match('/^\w+\(/', $v)) return $v; if (sql_test_int($type)) { if (is_numeric($v)) return $v; if (ctype_xdigit(substr($v,2)) AND strncmp($v,'0x',2)==0) return hexdec(substr($v,2)); } //else return ("'" . spip_sqlite_quote($v) . "'"); return (spip_sqlite_quote($v)); }