From: Claudio Sacerdoti Coen Date: Thu, 14 Jun 2007 11:07:45 +0000 (+0000) Subject: Incompatible syntax problem between MySql e Sqlite3 fixed. X-Git-Tag: 0.4.95@7852~397 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=748a6a2ba28c43e128759efbcc04919420e38cc1;p=helm.git Incompatible syntax problem between MySql e Sqlite3 fixed. --- diff --git a/components/hmysql/hMysql.ml b/components/hmysql/hMysql.ml index 76702b524..374ccc600 100644 --- a/components/hmysql/hMysql.ml +++ b/components/hmysql/hMysql.ml @@ -88,7 +88,6 @@ let errno = function | Mysql.No_such_table -> No_such_table | Mysql.Table_exists_error -> Table_exists_error | Mysql.Dup_keyname -> Dup_keyname - | Mysql.No_such_table -> No_such_table | Mysql.No_such_index -> No_such_index | Mysql.Bad_table_error -> Bad_table_error | _ -> GENERIC_ERROR "Mysql_generic_error" @@ -96,3 +95,4 @@ let errno = function let isMysql = true +let escape_string_for_like = ("ESCAPE \"\\\\\"" : ('a,'b,'c,'a) format4);; diff --git a/components/hmysql/hSql.mli b/components/hmysql/hSql.mli index 53600b5bf..fb678fa59 100644 --- a/components/hmysql/hSql.mli +++ b/components/hmysql/hSql.mli @@ -64,4 +64,6 @@ val errno : dbd -> error_code val escape: string -> string +val escape_string_for_like: ('a,'b,'c,'a) format4 + val isMysql : bool diff --git a/components/hmysql/hSqlite3.ml b/components/hmysql/hSqlite3.ml index da14a2f3f..20e494511 100644 --- a/components/hmysql/hSqlite3.ml +++ b/components/hmysql/hSqlite3.ml @@ -191,3 +191,5 @@ let errno = function ;; let isMysql = false + +let escape_string_for_like = ("ESCAPE \"\\\"" : ('a,'b,'c,'a) format4);; diff --git a/components/library/libraryClean.ml b/components/library/libraryClean.ml index 0a19d8d56..1b378e6c2 100644 --- a/components/library/libraryClean.ml +++ b/components/library/libraryClean.ml @@ -62,7 +62,7 @@ let one_step_depend suri = HLog.debug "Warning SELECT without REGEXP"; sprintf ("SELECT source, h_occurrence FROM %s WHERE " ^^ - "h_occurrence LIKE '%s%%' ESCAPE \"\\\"") + "h_occurrence LIKE '%s%%' " ^^ HSql.escape_string_for_like) obj_tbl buri*) end in @@ -103,7 +103,7 @@ let db_uris_of_baseuri buri = HLog.debug "Warning SELECT without REGEXP"; sprintf ("SELECT source, h_occurrence FROM %s WHERE " ^^ - "h_occurrence LIKE '%s%%' ESCAPE \"\\\" ") + "h_occurrence LIKE '%s%%' " ^^ HSql.escape_string_for_like) obj_tbl buri *) end diff --git a/components/library/libraryDb.ml b/components/library/libraryDb.ml index db8a8a506..e6af1eb81 100644 --- a/components/library/libraryDb.ml +++ b/components/library/libraryDb.ml @@ -168,7 +168,8 @@ let xpointers_of_ind uri = Pcre.replace ~pat:"([^\\\\])_" ~templ:"$1\\_" (HSql.escape s) in let query = sprintf - "SELECT source FROM %s WHERE source LIKE '%s#xpointer%%' ESCAPE \"\\\" " + ("SELECT source FROM %s WHERE source LIKE '%s#xpointer%%' " + ^^ HSql.escape_string_for_like) name_tbl (escape (UriManager.string_of_uri uri)) in let rc = HSql.exec dbd query in diff --git a/components/metadata/metadataDb.ml b/components/metadata/metadataDb.ml index 9480484c0..7678cd0b3 100644 --- a/components/metadata/metadataDb.ml +++ b/components/metadata/metadataDb.ml @@ -184,7 +184,9 @@ let clean ~(dbd:HSql.dbd) = Pcre.replace ~pat:"([^\\\\])_" ~templ:"$1\\_" (HSql.escape s) in let query s = - sprintf "DELETE FROM %s WHERE source LIKE \"%s%%\" ESCAPE \"\\\" " + sprintf + ("DELETE FROM %s WHERE source LIKE \"%s%%\" " ^^ + HSql.escape_string_for_like) (tbl ()) (escape s) in List.iter @@ -201,7 +203,9 @@ let unindex ~dbd ~uri = Pcre.replace ~pat:"([^\\\\])_" ~templ:"$1\\_" (HSql.escape s) in let query tbl = - sprintf "DELETE FROM %s WHERE source LIKE \"%s%%\" ESCAPE \"\\\" " + sprintf + ("DELETE FROM %s WHERE source LIKE \"%s%%\" " ^^ + HSql.escape_string_for_like) (tbl ()) (escape uri) in ignore (HSql.exec dbd (query tbl)) diff --git a/components/metadata/metadataDeps.ml b/components/metadata/metadataDeps.ml index bf1dc49e0..13e1d23b4 100644 --- a/components/metadata/metadataDeps.ml +++ b/components/metadata/metadataDeps.ml @@ -107,9 +107,10 @@ let sorted_uris_of_baseuri ~dbd baseuri = in let query = Printf.sprintf - ("SELECT source FROM %s WHERE source LIKE \"%s\" ESCAPE \"\\\" UNION " - ^^ - "SELECT source FROM %s WHERE source LIKE \"%s\" ESCAPE \"\\\"") + ("SELECT source FROM %s WHERE source LIKE \"%s\" " + ^^ HSql.escape_string_for_like ^^ " UNION " ^^ + "SELECT source FROM %s WHERE source LIKE \"%s\" " + ^^ HSql.escape_string_for_like) (MetadataTypes.name_tbl ()) sql_pat MetadataTypes.library_name_tbl sql_pat in diff --git a/components/whelp/whelp.ml b/components/whelp/whelp.ml index eb1f2b630..4a863eba8 100644 --- a/components/whelp/whelp.ml +++ b/components/whelp/whelp.ml @@ -47,9 +47,11 @@ let locate ~(dbd:HSql.dbd) ?(vars = false) pat = let sql_pat = sqlpat_of_shellglob pat in let query = sprintf - ("SELECT source FROM %s WHERE value LIKE \"%s\" ESCAPE \"\\\" " - ^^ "UNION " ^^ - "SELECT source FROM %s WHERE value LIKE \"%s\" ESCAPE \"\\\" ") + ("SELECT source FROM %s WHERE value LIKE \"%s\" " + ^^ HSql.escape_string_for_like + ^^ " UNION " ^^ + "SELECT source FROM %s WHERE value LIKE \"%s\" " + ^^ HSql.escape_string_for_like) (MetadataTypes.name_tbl ()) (escape sql_pat) MetadataTypes.library_name_tbl (escape sql_pat) in