-
-
Save parzibyte/3634c07c9d564274bd907fc19d4432f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func existeColumnaEnTabla(tabla string, columna string) (bool, error) { | |
bd, err := obtenerBaseDeDatos() | |
if err != nil { | |
return false, err | |
} | |
defer bd.Close() | |
filas, err := bd.Query(`PRAGMA table_info("` + tabla + `")`) | |
/* | |
Lo de PRAGMA regresa algo así: | |
cid|name|type|notnull|dflt_value|pk | |
"0" "id" "integer" "0" "1" | |
"1" "id_grupo" "integer" "0" "0" | |
"2" "nombre" "text" "1" "0" | |
"3" "direccion" "text" "1" "0" | |
"4" "genero" "text" "1" "0" | |
"5" "edad" "integer" "1" "0" | |
"6" "nombre_tutor" "text" "1" "0" | |
"7" "numero_tutor" "text" "1" "0" | |
*/ | |
if err != nil { | |
return false, err | |
} | |
defer filas.Close() | |
var cid string | |
var name string | |
var _type string // Con _ porque "type" es reservada | |
var notnull string | |
var dflt_value *string // Apuntador porque puede ser nulo, igual no no importa | |
var pk string | |
for filas.Next() { | |
err := filas.Scan(&cid, &name, &_type, ¬null, &dflt_value, &pk) | |
if err != nil { | |
return false, err | |
} | |
if name == columna { | |
return true, nil | |
} | |
} | |
return false, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment