SQLite

Check-in [84c268c3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix the PRAGMA case_sensitive_like command so that the LIKE function continues to be innocuous after the PRAGMA. Forum post 925dc9f67804c540.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 84c268c34cba7207a90dad2a8e972ce90c85304e91f4933c76963822ad1ae48b
User & Date: drh 2023-08-15 11:58:22
Context
2023-08-15
12:27
Use a dodgy substitute if the INFINITY macro is not available. See forumpost 8e66e19bb9. (check-in: 4ae72c89 user: drh tags: trunk)
11:58
Fix the PRAGMA case_sensitive_like command so that the LIKE function continues to be innocuous after the PRAGMA. Forum post 925dc9f67804c540. (check-in: 84c268c3 user: drh tags: trunk)
10:57
Fix an off-by-one error causing a buffer overread in test2.c. (check-in: e1edf95e user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/func.c.
2150
2151
2152
2153
2154
2155
2156

2157
2158

2159
2160
2161
2162
2163
2164
2165

2166
2167
2168
2169


2170
2171
2172
2173
2174
2175
2176

/*
** Re-register the built-in LIKE functions.  The caseSensitive
** parameter determines whether or not the LIKE operator is case
** sensitive.
*/
void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){

  struct compareInfo *pInfo;
  int flags;

  if( caseSensitive ){
    pInfo = (struct compareInfo*)&likeInfoAlt;
    flags = SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE;
  }else{
    pInfo = (struct compareInfo*)&likeInfoNorm;
    flags = SQLITE_FUNC_LIKE;
  }

  sqlite3CreateFunc(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0, 0, 0);
  sqlite3CreateFunc(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0, 0, 0);
  sqlite3FindFunction(db, "like", 2, SQLITE_UTF8, 0)->funcFlags |= flags;
  sqlite3FindFunction(db, "like", 3, SQLITE_UTF8, 0)->funcFlags |= flags;


}

/*
** pExpr points to an expression which implements a function.  If
** it is appropriate to apply the LIKE optimization to that function
** then set aWc[0] through aWc[2] to the wildcard characters and the
** escape character and then return TRUE.  If the function is not a







>


>







>
|
|
|
|
>
>







2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181

/*
** Re-register the built-in LIKE functions.  The caseSensitive
** parameter determines whether or not the LIKE operator is case
** sensitive.
*/
void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
  FuncDef *pDef;
  struct compareInfo *pInfo;
  int flags;
  int nArg;
  if( caseSensitive ){
    pInfo = (struct compareInfo*)&likeInfoAlt;
    flags = SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE;
  }else{
    pInfo = (struct compareInfo*)&likeInfoNorm;
    flags = SQLITE_FUNC_LIKE;
  }
  for(nArg=2; nArg<=3; nArg++){
    sqlite3CreateFunc(db, "like", nArg, SQLITE_UTF8, pInfo, likeFunc, 
                      0, 0, 0, 0, 0);
    pDef = sqlite3FindFunction(db, "like", nArg, SQLITE_UTF8, 0);
    pDef->funcFlags |= flags;
    pDef->funcFlags &= ~SQLITE_FUNC_UNSAFE;
  }
}

/*
** pExpr points to an expression which implements a function.  If
** it is appropriate to apply the LIKE optimization to that function
** then set aWc[0] through aWc[2] to the wildcard characters and the
** escape character and then return TRUE.  If the function is not a
Changes to test/like.test.
1135
1136
1137
1138
1139
1140
1141




















1142
1143

# 2021-02-15 ticket c0aeea67d58ae0fd
#
do_execsql_test 17.1 {
  SELECT 'x' LIKE '%' ESCAPE '_';
} {1}






















finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163

# 2021-02-15 ticket c0aeea67d58ae0fd
#
do_execsql_test 17.1 {
  SELECT 'x' LIKE '%' ESCAPE '_';
} {1}


# 2023-08-15 https://sqlite.org/forum/forumpost/925dc9f67804c540
#
reset_db
sqlite3_db_config db DEFENSIVE 1
db eval {PRAGMA trusted_schema=OFF}
do_execsql_test 18.0 {
  CREATE TABLE t1(x INT, y TEXT);
  INSERT INTO t1 VALUES(1,'abc'),(2,'ABC'),(3,'Abc');
  CREATE VIEW t2 AS SELECT * FROM t1 WHERE y LIKE 'a%';
  SELECT * FROM t2;
} {1 abc 2 ABC 3 Abc}
do_execsql_test 18.1 {
  PRAGMA case_sensitive_like=OFF;
  SELECT * FROM t2;
} {1 abc 2 ABC 3 Abc}
do_execsql_test 18.2 {
  PRAGMA case_sensitive_like=ON;
  SELECT * FROM t2;
} {1 abc}

finish_test