From 0f3aa13cca7b39bf21b82738e1c183bc6c9e6ae3 Mon Sep 17 00:00:00 2001 From: Claudio Sacerdoti Coen Date: Thu, 14 Jun 2007 11:07:45 +0000 Subject: [PATCH] Incompatible syntax problem between MySql e Sqlite3 fixed. --- helm/software/components/hmysql/hMysql.ml | 2 +- helm/software/components/hmysql/hSql.mli | 2 ++ helm/software/components/hmysql/hSqlite3.ml | 2 ++ helm/software/components/library/libraryClean.ml | 4 ++-- helm/software/components/library/libraryDb.ml | 3 ++- helm/software/components/metadata/metadataDb.ml | 8 ++++++-- helm/software/components/metadata/metadataDeps.ml | 7 ++++--- helm/software/components/whelp/whelp.ml | 8 +++++--- 8 files changed, 24 insertions(+), 12 deletions(-) diff --git a/helm/software/components/hmysql/hMysql.ml b/helm/software/components/hmysql/hMysql.ml index 76702b524..374ccc600 100644 --- a/helm/software/components/hmysql/hMysql.ml +++ b/helm/software/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/helm/software/components/hmysql/hSql.mli b/helm/software/components/hmysql/hSql.mli index 53600b5bf..fb678fa59 100644 --- a/helm/software/components/hmysql/hSql.mli +++ b/helm/software/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/helm/software/components/hmysql/hSqlite3.ml b/helm/software/components/hmysql/hSqlite3.ml index da14a2f3f..20e494511 100644 --- a/helm/software/components/hmysql/hSqlite3.ml +++ b/helm/software/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/helm/software/components/library/libraryClean.ml b/helm/software/components/library/libraryClean.ml index 0a19d8d56..1b378e6c2 100644 --- a/helm/software/components/library/libraryClean.ml +++ b/helm/software/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/helm/software/components/library/libraryDb.ml b/helm/software/components/library/libraryDb.ml index db8a8a506..e6af1eb81 100644 --- a/helm/software/components/library/libraryDb.ml +++ b/helm/software/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/helm/software/components/metadata/metadataDb.ml b/helm/software/components/metadata/metadataDb.ml index 9480484c0..7678cd0b3 100644 --- a/helm/software/components/metadata/metadataDb.ml +++ b/helm/software/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/helm/software/components/metadata/metadataDeps.ml b/helm/software/components/metadata/metadataDeps.ml index bf1dc49e0..13e1d23b4 100644 --- a/helm/software/components/metadata/metadataDeps.ml +++ b/helm/software/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/helm/software/components/whelp/whelp.ml b/helm/software/components/whelp/whelp.ml index eb1f2b630..4a863eba8 100644 --- a/helm/software/components/whelp/whelp.ml +++ b/helm/software/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 -- 2.39.2