Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: imeevma@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v5 5/5] sql: refactor PRAGMA-related code
Date: Fri, 27 Dec 2019 18:26:42 +0300	[thread overview]
Message-ID: <3efcf01a-2830-b5de-246c-e15d738612c6@tarantool.org> (raw)
In-Reply-To: <a0e48bc6f45392b9bf50aa47c6380926359f0356.1577445318.git.imeevma@gmail.com>

Thanks for the patch!

I've pushed my review fixes on top of this commit. See it below
and on the branch. If you agree, then squash. Otherwise lets
discuss.

================================================================================

commit 253847585514e0abc0f098c13ab77048a807d8d1
Author: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Date:   Fri Dec 27 18:22:53 2019 +0300

    Review fixes 5/5

diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c
index 3f3dac3be..28ba64500 100644
--- a/src/box/sql/pragma.c
+++ b/src/box/sql/pragma.c
@@ -237,15 +237,12 @@ sql_pragma_collation_list(struct Parse *parse_context)
 {
 	struct Vdbe *v = sqlGetVdbe(parse_context);
 	assert(v != NULL);
-	int i = 0;
-	struct space *space = space_by_name("_collation");
 	/* 16 is enough to encode 0 len array */
 	char key_buf[16];
-	char *key_end = key_buf;
-	key_end = mp_encode_array(key_end, 0);
+	char *key_end = mp_encode_array(key_buf, 0);
 	box_tuple_t *tuple;
-	box_iterator_t* it;
-	it = box_index_iterator(space->def->id, 0, ITER_ALL, key_buf, key_end);
+	box_iterator_t *it = box_index_iterator(BOX_COLLATION_ID, 0, ITER_ALL,
+						key_buf, key_end);
 	if (it == NULL) {
 		parse_context->is_aborted = true;
 		return;
@@ -253,9 +250,9 @@ sql_pragma_collation_list(struct Parse *parse_context)
 	int rc = box_iterator_next(it, &tuple);
 	assert(rc == 0);
 	(void) rc;
-	for (i = 0; tuple != NULL; i++, box_iterator_next(it, &tuple)) {
-		/* 1 is name field number */
-		const char *str = tuple_field_cstr(tuple, 1);
+	for (int i = 0; tuple != NULL; i++, box_iterator_next(it, &tuple)) {
+		const char *str = tuple_field_cstr(tuple,
+						   BOX_COLLATION_FIELD_NAME);
 		assert(str != NULL);
 		/* this procedure should reallocate and copy str */
 		sqlVdbeMultiLoad(v, 1, "is", i, str);
@@ -309,18 +306,18 @@ sql_pragma_foreign_key_list(struct Parse *parse_context, const char *table_name)
 	struct fk_constraint *fk_c;
 	rlist_foreach_entry(fk_c, &space->child_fk_constraint, in_child_space) {
 		struct fk_constraint_def *fk_def = fk_c->def;
+		struct space *parent = space_by_id(fk_def->parent_id);
+		assert(parent != NULL);
+		const char *on_delete_action =
+			fk_constraint_action_strs[fk_def->on_delete];
+		const char *on_update_action =
+			fk_constraint_action_strs[fk_def->on_update];
 		for (uint32_t j = 0; j < fk_def->field_count; j++) {
-			struct space *parent = space_by_id(fk_def->parent_id);
-			assert(parent != NULL);
 			uint32_t ch_fl = fk_def->links[j].child_field;
 			const char *child_col = space->def->fields[ch_fl].name;
 			uint32_t pr_fl = fk_def->links[j].parent_field;
 			const char *parent_col =
 				parent->def->fields[pr_fl].name;
-			const char *on_delete_action =
-				fk_constraint_action_strs[fk_def->on_delete];
-			const char *on_update_action =
-				fk_constraint_action_strs[fk_def->on_update];
 			sqlVdbeMultiLoad(v, 1, "iissssss", i, j,
 					 parent->def->name, child_col,
 					 parent_col, on_delete_action,
@@ -332,21 +329,20 @@ sql_pragma_foreign_key_list(struct Parse *parse_context, const char *table_name)
 }
 
 void
-sqlPragma(Parse *pParse, Token *pragma, Token *table, Token *index)
+sqlPragma(struct Parse *pParse, struct Token *pragma, struct Token *table,
+	  struct Token *index)
 {
-	char *pragma_name = NULL;
 	char *table_name = NULL;
 	char *index_name = NULL;
-	sql *db = pParse->db;
-	Vdbe *v = sqlGetVdbe(pParse);
-	const struct PragmaName *pPragma;
+	struct sql *db = pParse->db;
+	struct Vdbe *v = sqlGetVdbe(pParse);
 
 	if (v == NULL)
 		return;
 	sqlVdbeRunOnlyOnce(v);
 	pParse->nMem = 2;
 
-	pragma_name = sql_name_from_token(db, pragma);
+	char *pragma_name = sql_name_from_token(db, pragma);
 	if (pragma_name == NULL) {
 		pParse->is_aborted = true;
 		goto pragma_out;
@@ -367,7 +363,7 @@ sqlPragma(Parse *pParse, Token *pragma, Token *table, Token *index)
 	}
 
 	/* Locate the pragma in the lookup table */
-	pPragma = pragmaLocate(pragma_name);
+	const struct PragmaName *pPragma = pragmaLocate(pragma_name);
 	if (pPragma == 0) {
 		diag_set(ClientError, ER_SQL_NO_SUCH_PRAGMA, pragma_name);
 		pParse->is_aborted = true;
diff --git a/src/box/sql/pragma.h b/src/box/sql/pragma.h
index 178746b35..f319272d4 100644
--- a/src/box/sql/pragma.h
+++ b/src/box/sql/pragma.h
@@ -1,17 +1,11 @@
 /** List of ID of pragmas. */
 enum
 {
-	/** Pragma collation_list. */
 	PRAGMA_COLLATION_LIST = 0,
-	/** Pragma foreign_key_list. */
 	PRAGMA_FOREIGN_KEY_LIST,
-	/** Pragma index_info. */
 	PRAGMA_INDEX_INFO,
-	/** Pragma index_list. */
 	PRAGMA_INDEX_LIST,
-	/** Pragma stats. */
 	PRAGMA_STATS,
-	/** Pragma table_info. */
 	PRAGMA_TABLE_INFO,
 };
 
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 4691a3369..1d8f6c8cd 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -2781,7 +2781,8 @@ int sqlInit(sql *);
  * @param index Name of the index.
  */
 void
-sqlPragma(Parse *pParse, Token *pragma, Token *table, Token *index);
+sqlPragma(struct Parse *pParse, struct Token *pragma, struct Token *table,
+	  struct Token *index);
 
 /**
  * Return true if given column is part of primary key.

  reply	other threads:[~2019-12-27 15:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-27 11:18 [Tarantool-patches] [PATCH v5 0/5] Remove control pragmas imeevma
2019-12-27 11:18 ` [Tarantool-patches] [PATCH v5 1/5] sql: remove PRAGMA "count_changes" imeevma
2019-12-27 11:18 ` [Tarantool-patches] [PATCH v5 2/5] sql: remove PRAGMA "short_column_names" imeevma
2019-12-27 16:55   ` Nikita Pettik
2019-12-29 12:58     ` Mergen Imeev
2019-12-27 11:18 ` [Tarantool-patches] [PATCH v5 3/5] sql: remove PRAGMA "sql_compound_select_limit" imeevma
2019-12-27 11:18 ` [Tarantool-patches] [PATCH v5 4/5] sql: remove control pragmas imeevma
2019-12-27 15:26   ` Vladislav Shpilevoy
2019-12-29 12:44     ` Mergen Imeev
2019-12-29 12:59       ` Mergen Imeev
2019-12-29 13:23         ` Mergen Imeev
2019-12-27 11:18 ` [Tarantool-patches] [PATCH v5 5/5] sql: refactor PRAGMA-related code imeevma
2019-12-27 15:26   ` Vladislav Shpilevoy [this message]
2019-12-29 12:46     ` Mergen Imeev
2019-12-30 10:19 [Tarantool-patches] [PATCH v5 0/5] Remove control pragmas imeevma
2019-12-30 10:19 ` [Tarantool-patches] [PATCH v5 5/5] sql: refactor PRAGMA-related code imeevma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3efcf01a-2830-b5de-246c-e15d738612c6@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v5 5/5] sql: refactor PRAGMA-related code' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox