Line data Source code
1 : /** 2 : Copyright (c) 2022 Roman Katuntsev <sbkarr@stappler.org> 3 : Copyright (c) 2023 Stappler LLC <admin@stappler.dev> 4 : 5 : Permission is hereby granted, free of charge, to any person obtaining a copy 6 : of this software and associated documentation files (the "Software"), to deal 7 : in the Software without restriction, including without limitation the rights 8 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 : copies of the Software, and to permit persons to whom the Software is 10 : furnished to do so, subject to the following conditions: 11 : 12 : The above copyright notice and this permission notice shall be included in 13 : all copies or substantial portions of the Software. 14 : 15 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 : THE SOFTWARE. 22 : **/ 23 : 24 : #include "SPSql.h" 25 : 26 : namespace STAPPLER_VERSIONIZED stappler::sql { 27 : 28 0 : Pair<StringView, bool> encodeComparation(Comparation cmp) { 29 0 : bool isTwoArgs = false; 30 0 : StringView ret; 31 : 32 0 : switch (cmp) { 33 0 : case Comparation::Invalid: break; 34 0 : case Comparation::LessThen: ret = StringView("lt"); break; 35 0 : case Comparation::LessOrEqual: ret = StringView("le"); break; 36 0 : case Comparation::Equal: ret = StringView("eq"); break; 37 0 : case Comparation::NotEqual: ret = StringView("neq"); break; 38 0 : case Comparation::GreatherOrEqual: ret = StringView("ge"); break; 39 0 : case Comparation::GreatherThen: ret = StringView("gt"); break; 40 0 : case Comparation::BetweenValues: ret = StringView("bw"); isTwoArgs = true; break; 41 0 : case Comparation::BetweenEquals: ret = StringView("be"); isTwoArgs = true; break; 42 0 : case Comparation::NotBetweenValues: ret = StringView("nbw"); isTwoArgs = true; break; 43 0 : case Comparation::NotBetweenEquals: ret = StringView("nbe"); isTwoArgs = true; break; 44 0 : case Comparation::Includes: ret = StringView("incl"); break; 45 0 : case Comparation::Between: ret = StringView("sbw"); isTwoArgs = true; break; 46 0 : case Comparation::In: ret = StringView("in"); break; 47 0 : case Comparation::NotIn: ret = StringView("notin"); break; 48 0 : case Comparation::IsNull: ret = StringView("isnull"); break; 49 0 : case Comparation::IsNotNull: ret = StringView("isnotnull"); break; 50 0 : case Comparation::Suffix: ret = StringView("suffix"); break; 51 0 : case Comparation::Prefix: ret = StringView("prefix"); break; 52 0 : case Comparation::WordPart: ret = StringView("wordpart"); break; 53 : } 54 : 55 0 : return pair(move(ret), isTwoArgs); 56 : } 57 : 58 350 : Pair<Comparation, bool> decodeComparation(StringView str) { 59 350 : bool isTwoArgs = false; 60 350 : Comparation ret = Comparation::Invalid; 61 : 62 350 : if (str == "lt") { 63 25 : ret = Comparation::LessThen; 64 325 : } else if (str == "le") { 65 0 : ret = Comparation::LessOrEqual; 66 325 : } else if (str == "eq") { 67 25 : ret = Comparation::Equal; 68 300 : } else if (str == "neq") { 69 0 : ret = Comparation::NotEqual; 70 300 : } else if (str == "ge") { 71 0 : ret = Comparation::GreatherOrEqual; 72 300 : } else if (str == "gt") { 73 25 : ret = Comparation::GreatherThen; 74 275 : } else if (str == "bw") { 75 25 : ret = Comparation::BetweenValues; isTwoArgs = true; 76 250 : } else if (str == "be") { 77 0 : ret = Comparation::BetweenEquals; isTwoArgs = true; 78 250 : } else if (str == "nbw") { 79 0 : ret = Comparation::NotBetweenValues; isTwoArgs = true; 80 250 : } else if (str == "nbe") { 81 0 : ret = Comparation::NotBetweenEquals; isTwoArgs = true; 82 250 : } else if (str == "incl") { 83 0 : ret = Comparation::Includes; 84 250 : } else if (str == "sbw") { 85 0 : ret = Comparation::Between; isTwoArgs = true; 86 250 : } else if (str == "in") { 87 0 : ret = Comparation::In; 88 250 : } else if (str == "notin") { 89 0 : ret = Comparation::NotIn; 90 250 : } else if (str == "isnull") { 91 0 : ret = Comparation::IsNull; 92 250 : } else if (str == "isnotnull") { 93 0 : ret = Comparation::IsNotNull; 94 250 : } else if (str == "prefix") { 95 0 : ret = Comparation::Prefix; 96 250 : } else if (str == "suffix") { 97 0 : ret = Comparation::Suffix; 98 250 : } else if (str == "wordpart") { 99 0 : ret = Comparation::WordPart; 100 : } 101 : 102 700 : return pair(ret, isTwoArgs); 103 : } 104 : 105 : }