Mercurial > urweb
comparison src/mysql.sml @ 998:ad434669f299
Fix some MySQL hijinks
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Mon, 12 Oct 2009 18:16:42 -0400 |
parents | 6b1d960e2616 |
children | 16f7cb0891b6 |
comparison
equal
deleted
inserted
replaced
997:588b31fe6cc9 | 998:ad434669f299 |
---|---|
71 | ch => str ch) | 71 | ch => str ch) |
72 | 72 |
73 fun checkRel (table, checkNullable) (s, xts) = | 73 fun checkRel (table, checkNullable) (s, xts) = |
74 let | 74 let |
75 val sl = CharVector.map Char.toLower s | 75 val sl = CharVector.map Char.toLower s |
76 | 76 val both = "table_name IN ('" ^ sl ^ "', '" ^ s ^ "')" |
77 val q = "SELECT COUNT(*) FROM information_schema." ^ table ^ " WHERE table_name = '" | 77 |
78 ^ sl ^ "'" | 78 val q = "SELECT COUNT(*) FROM information_schema." ^ table ^ " WHERE " ^ both |
79 | 79 |
80 val q' = String.concat ["SELECT COUNT(*) FROM information_schema.columns WHERE table_name = '", | 80 val q' = String.concat ["SELECT COUNT(*) FROM information_schema.columns WHERE ", |
81 sl, | 81 both, |
82 "' AND (", | 82 " AND (", |
83 String.concatWith " OR " | 83 String.concatWith " OR " |
84 (map (fn (x, t) => | 84 (map (fn (x, t) => |
85 String.concat ["(column_name = 'uw_", | 85 String.concat ["(column_name IN ('uw_", |
86 CharVector.map | 86 CharVector.map |
87 Char.toLower (ident x), | 87 Char.toLower (ident x), |
88 "' AND data_type = '", | 88 "', 'uw_", |
89 ident x, | |
90 "') AND data_type = '", | |
89 p_sql_type_base t, | 91 p_sql_type_base t, |
90 "'", | 92 "'", |
91 if checkNullable then | 93 if checkNullable then |
92 (" AND is_nullable = '" | 94 (" AND is_nullable = '" |
93 ^ (if isNotNull t then | 95 ^ (if isNotNull t then |
98 else | 100 else |
99 "", | 101 "", |
100 ")"]) xts), | 102 ")"]) xts), |
101 ")"] | 103 ")"] |
102 | 104 |
103 val q'' = String.concat ["SELECT COUNT(*) FROM information_schema.columns WHERE table_name = '", | 105 val q'' = String.concat ["SELECT COUNT(*) FROM information_schema.columns WHERE ", |
104 sl, | 106 both, |
105 "' AND column_name LIKE 'uw_%'"] | 107 " AND column_name LIKE 'uw_%'"] |
106 in | 108 in |
107 box [string "if (mysql_query(conn->conn, \"", | 109 box [string "if (mysql_query(conn->conn, \"", |
108 string q, | 110 string q, |
109 string "\")) {", | 111 string "\")) {", |
110 newline, | 112 newline, |