Skip to content

Commit 1b2f666

Browse files
committed
remove setstr
1 parent bb94597 commit 1b2f666

File tree

11 files changed

+19
-575
lines changed

11 files changed

+19
-575
lines changed

docs/latex/sections/gufi_query.tex

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -212,68 +212,6 @@ \subsubsection{Short Circuiting with Compound Queries}
212212
To turn off short circuiting and always run all queries for each
213213
directory, pass the \texttt{-a} flag to \gufiquery.
214214

215-
\subsubsection{User String Replacement}
216-
\label{sec:user_strings}
217-
Queries may have string replacements done to them before being run on
218-
a particular directory.
219-
220-
After calling \texttt{setstr(`key', value)} in one SQL input argument,
221-
\texttt{\{key\}} can be used in a later SQL input argument to do
222-
string replacements. The key can be any string with at least 1
223-
character. Duplicate keys will replace previously defined values.
224-
225-
Note that the key and value will only be available to the thread where
226-
it was processed. Each thread should set their own instances of the
227-
key.
228-
\\\\
229-
\noindent Example Usage:
230-
\begin{table}[H]
231-
\centering
232-
\begin{tabular}{ll}
233-
\gufiquery & \texttt{-S "SELECT setstr(`key', (SELECT 123));"} \\
234-
& \texttt{-E "SELECT \{key\};"} \\
235-
& \indexroot \\
236-
\end{tabular}
237-
\end{table}
238-
239-
SQL statements combining setting and using values into one input
240-
argument will not work because the entire string will have been parsed
241-
by \sqlite before replacements can happen. \\
242-
243-
\noindent Bad Usage:
244-
\begin{table}[H]
245-
\centering
246-
\begin{tabular}{ll}
247-
\gufiquery & \texttt{-S "SELECT setstr(`key', (SELECT 123)); SELECT \{key\};"} \\
248-
& \indexroot \\
249-
\end{tabular}
250-
\end{table}
251-
252-
Additionally, a few user strings are predefined for convenience. They
253-
were previously part of the deprecated \texttt{\% Formatting}, and
254-
have been moved here.
255-
256-
\begin{table}[H]
257-
\centering
258-
\begin{tabular}{|l|l|}
259-
\hline
260-
User String & Explanation \\
261-
\hline
262-
\texttt{n} & Replace with the current index directory's name \\
263-
\hline
264-
\texttt{i} & Replace with the current index directory's path \\
265-
\hline
266-
\texttt{s} & Replace with the source path of this directory \\
267-
& (Requires \texttt{-p}) \\
268-
\hline
269-
\end{tabular}
270-
\caption{Predefined User Strings}
271-
\end{table}
272-
273-
These strings may be redefined by the user. However, \texttt{n} and
274-
\texttt{i} will be reset at the beginning of the next directory's
275-
processing.
276-
277215
\subsubsection{Extended Attributes}
278216
\label{sec:query_xattrs}
279217
When querying for xattrs, pass \texttt{-x} to \gufiquery to build the

include/gufi_query/process_queries.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,9 @@ OF SUCH DAMAGE.
7171
#include "bf.h"
7272
#include "gufi_query/PoolArgs.h"
7373
#include "gufi_query/gqw.h"
74-
#include "trie.h"
7574

7675
int process_queries(PoolArgs_t *pa, QPTPool_t *ctx, const int id,
77-
DIR *dir, gqw_t *gqw, sqlite3 *db, trie_t *user_strs,
76+
DIR *dir, gqw_t *gqw, sqlite3 *db,
7877
const char *dbname, const size_t dbname_len,
7978
const int descend, size_t *subdirs_walked_count);
8079

include/gufi_query/query_replacement.h

Lines changed: 0 additions & 88 deletions
This file was deleted.

include/gufi_query/query_user_strs.h

Lines changed: 0 additions & 104 deletions
This file was deleted.

src/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ add_library(gufi_query_lib OBJECT
189189
gufi_query/process_queries.c
190190
gufi_query/processdir.c
191191
gufi_query/query.c
192-
gufi_query/query_replacement.c
193-
gufi_query/query_user_strs.c
194192
)
195193

196194
if (DEP_AI)

src/gufi_query/PoolArgs.c

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -74,39 +74,6 @@ OF SUCH DAMAGE.
7474
#include "gufi_query/external.h"
7575
#include "gufi_query/per_thread_kv.h"
7676

77-
/* don't introduce undefined behavior by casting function when passing into trie_insert */
78-
static void str_free_wrapper(void *str) {
79-
str_free((str_t *) str);
80-
}
81-
82-
/*
83-
* udf that allows for user to name SQL values that can be used for string replacement
84-
*
85-
* -S "SELECT setstr('1', (SELECT col ...));"
86-
* -E "SELECT '{1}';"
87-
*
88-
* will print the value of col
89-
*/
90-
static void setstr(sqlite3_context *context, int argc, sqlite3_value **argv) {
91-
(void) argc;
92-
93-
trie_t *user_strs = (trie_t *) sqlite3_user_data(context);
94-
95-
/* args are cast to strings */
96-
97-
const size_t key_len = sqlite3_value_bytes(argv[0]);
98-
const char *key = (const char *) sqlite3_value_text(argv[0]);
99-
100-
const size_t val_len = sqlite3_value_bytes(argv[1]);
101-
const char *val = (const char *) sqlite3_value_text(argv[1]);
102-
103-
/* copy value since its lifetime is not guaranteed */
104-
str_t *copy = str_alloc(val_len);
105-
memcpy(copy->data, val, val_len);
106-
107-
trie_insert(user_strs, key, key_len, copy, str_free_wrapper);
108-
}
109-
11077
void thread_id(sqlite3_context *context, int argc, sqlite3_value **argv) {
11178
(void) argc; (void) argv;
11279

@@ -156,30 +123,15 @@ int PoolArgs_init(PoolArgs_t *pa, struct input *in, pthread_mutex_t *global_mute
156123
break;
157124
}
158125

159-
/* user string storage */
160-
ta->user_strs = trie_alloc();
161-
162-
/*
163-
* {s} defaults to the source tree path - can change, but generally will not
164-
*
165-
* maybe move this into processdir to reset the value every time?
166-
*/
167-
if (in->sql_format.source_prefix.data && in->sql_format.source_prefix.len) {
168-
trie_insert(ta->user_strs, "s", 1, &in->sql_format.source_prefix, NULL);
169-
}
170-
171-
if (sqlite3_create_function(ta->outdb, "setstr", 2, SQLITE_UTF8,
172-
ta->user_strs, &setstr, NULL, NULL) != SQLITE_OK) {
173-
fprintf(stderr, "Error: Could not add setstr to sqlite\n");
174-
break;
175-
}
176-
177126
/* create a simple kv table and functions to set and get */
178127
if (ptkv_init(ta->outdb) != SQLITE_OK) {
179128
break;
180129
}
181130

182-
/* set key s with the source tree path - can change, but generally will not */
131+
/* set key s with the source tree path - can change, but generally will not
132+
*
133+
* maybe move this into processdir to reset the value every time?
134+
*/
183135
if (in->sql_format.source_prefix.data && in->sql_format.source_prefix.len) {
184136
if (ptkv_set_internal(i, ta->outdb, "s", 1, &in->sql_format.source_prefix) != SQLITE_OK) {
185137
break;
@@ -294,8 +246,6 @@ void PoolArgs_fin(PoolArgs_t *pa, const size_t allocated) {
294246

295247
closedb(ta->outdb);
296248

297-
trie_free(ta->user_strs);
298-
299249
if (ta->outfile) {
300250
OutputBuffer_flush(&ta->output_buffer, ta->outfile);
301251
}

src/gufi_query/handle_sql.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ OF SUCH DAMAGE.
6767

6868
#include "dbutils.h"
6969
#include "gufi_query/handle_sql.h"
70-
#include "gufi_query/query_replacement.h"
7170
#include "template_db.h"
7271

7372
static int validate(struct input *in) {
@@ -220,13 +219,6 @@ static int gen_types(struct input *in) {
220219
return -1;
221220
}
222221

223-
static int sql_formatting(struct input *in) {
224-
save_replacements(&in->sql.tsum, &in->sql_format.tsum);
225-
save_replacements(&in->sql.sum, &in->sql_format.sum);
226-
save_replacements(&in->sql.ent, &in->sql_format.ent);
227-
return 0;
228-
}
229-
230222
int handle_sql(struct input *in) {
231223
if (validate(in) != 0) {
232224
return -1;
@@ -236,9 +228,5 @@ int handle_sql(struct input *in) {
236228
return -1;
237229
}
238230

239-
if (sql_formatting(in) != 0) {
240-
return -1;
241-
}
242-
243231
return 0;
244232
}

0 commit comments

Comments
 (0)