コード例 #1
0
ファイル: tnt_sql.c プロジェクト: tarantool/migrate
/*
 * tnt_query_is()
 *
 * Tells if the supplied query should be processed as SQL.
 *
 * q     - sql query string
 * qsize - query size
 * 
 * returns 1 if yes, 0 otherwise.
*/
int
tnt_query_is(char *q, size_t qsize)
{
	struct tnt_lex l;
	if (!tnt_lex_init(&l, tnt_sql_keywords, (unsigned char*)q, qsize))
		return 0;
	int rc = 0;
	struct tnt_tk *tk;
	switch (tnt_lex(&l, &tk)) {
	case TNT_TK_ERROR:
	case TNT_TK_EOF:
		break;
	default:
		if (tk->tk == TNT_TK_PING    ||
		    tk->tk == TNT_TK_INSERT  ||
		    tk->tk == TNT_TK_REPLACE ||
		    tk->tk == TNT_TK_UPDATE  ||
		    tk->tk == TNT_TK_SELECT  ||
		    tk->tk == TNT_TK_DELETE  ||
		    tk->tk == TNT_TK_CALL)
			rc = 1;
		break;
	}
	tnt_lex_free(&l);
	return rc;
}
コード例 #2
0
ファイル: tnt_sql.c プロジェクト: tarantool/migrate
/*
 * tnt_query()
 *
 * Parses and processes supplied SQL query;
 *
 * s     - stream pointer
 * q     - sql query string
 * qsize - query size
 * e     - error description string
 * 
 * returns 0 on success, or -1 on error
 * and string description returned (must be freed after use).
*/
int
tnt_query(struct tnt_stream *s, const char *q, size_t qsize, char **e)
{
	struct tnt_lex l;
	if (!tnt_lex_init(&l, tnt_sql_keywords, (unsigned char*)q, qsize))
		return -1;
	struct tnt_sql sql = { s, &l, NULL };
	bool ret = tnt_sql(&sql);
	if (e) {
		*e = sql.error;
	} else {
		if (sql.error)
			tnt_mem_free(sql.error);
	}
	tnt_lex_free(&l);
	return (ret) ? 0 : -1;
}
コード例 #3
0
ファイル: nb_config.c プロジェクト: iDevy/nosqlbench
int nb_config_parse(char *file)
{
	char *buf = NULL;
	size_t size;

	if (nb_config_readfile(file, &buf, &size) == -1)
		return -1;

	struct nb_config cfg;
	memset(&cfg, 0, sizeof(cfg));

	if (tnt_lex_init(&cfg.lex, nb_lex_keywords, (unsigned char*)buf,
			 size) == -1) {
		free(buf);
		return -1;
	}
	free(buf);

	cfg.file = file;
	int rc = nb_config_process(&cfg);

	tnt_lex_free(&cfg.lex);
	return rc;
}