Código PHP:
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
Aca esta utilizando el operador ternario.
Si esta definida la directiva get_magic_quotes_gpc() en el php.ini, le quita los slashes o el "escape de las comillas simples" a el valor para consultar que esta en la variable $theValue, lo que hace magic_quotes_gpc es escapar automaticamente a todas las variables que pases con $_GET o $_POST. Es decir si pasaste pagina.php?Busqueda=Esta ' Es la busqueda, automaticamente sin que tengas que utilizar la funcion magic_quotes_gpc lo dejara asi Esta \' Es la busqueda.
En este caso lo quita automaticamente.
Y luego
Código PHP:
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
Hace lo mismo, si se puede utilizar la funcion mysql_real_escape_string lo hace por real_scape_string, sino lo hace por mysql_escape_string.
La funcion mysqsl_escape_string actua similarmente a addslashes...
Pero dicen por ahi que es mejor...
En todo caso lo que hace es escapar tambien las comillas, caracteres especiales...
etc.
Código PHP:
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
Este switch convierte al tipo que le pasaste a la funcion, a la variable que le pasaste.
Por ejemplo si le pasas double, te devuelve el valor entero de la variable, y le agrega las comillas para anidarlo a la consulta.
si le pasaste por ejemplo...
GetSQLValueString(175.6,'double');
la funcion te va a retornar el valor entero y escapado con las comillas agregadas de 175.6
es decir '175.6'
pero no lo hace para el valor int
Lo que no entendi en verdad es:
Código PHP:
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
ya que no afecta a la variable $theValue, ni tampoco retorna nada......
es decir no va a hacer nada si le pasas GetSQLValueString(175.6,'defined','cualquiercosa', 'cualquiercosa');
Saludos.