summaryrefslogtreecommitdiffstats
path: root/third_party/rust/sql-support/src/lib.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/sql-support/src/lib.rs
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/sql-support/src/lib.rs')
-rw-r--r--third_party/rust/sql-support/src/lib.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/third_party/rust/sql-support/src/lib.rs b/third_party/rust/sql-support/src/lib.rs
new file mode 100644
index 0000000000..17068dcfea
--- /dev/null
+++ b/third_party/rust/sql-support/src/lib.rs
@@ -0,0 +1,36 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#![allow(unknown_lints)]
+#![warn(rust_2018_idioms)]
+
+mod conn_ext;
+mod each_chunk;
+mod maybe_cached;
+pub mod open_database;
+mod repeat;
+
+pub use crate::conn_ext::*;
+pub use crate::each_chunk::*;
+pub use crate::maybe_cached::*;
+pub use crate::repeat::*;
+
+/// In PRAGMA foo='bar', `'bar'` must be a constant string (it cannot be a
+/// bound parameter), so we need to escape manually. According to
+/// https://www.sqlite.org/faq.html, the only character that must be escaped is
+/// the single quote, which is escaped by placing two single quotes in a row.
+pub fn escape_string_for_pragma(s: &str) -> String {
+ s.replace('\'', "''")
+}
+
+#[cfg(test)]
+mod test {
+ use super::*;
+ #[test]
+ fn test_escape_string_for_pragma() {
+ assert_eq!(escape_string_for_pragma("foobar"), "foobar");
+ assert_eq!(escape_string_for_pragma("'foo'bar'"), "''foo''bar''");
+ assert_eq!(escape_string_for_pragma("''"), "''''");
+ }
+}