[tarantool-patches] Re: [PATCH 6/6] sql: allow to specify UNSIGNED column type

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Fri Jul 12 00:25:04 MSK 2019


As I promised, below are other comments regarding Mem.u.i/u,
MEM_Int/UInt. Perhaps, they are final.

-------------------------
vdbemem.c:661

> 	if ((pMem->flags & MEM_Blob) != 0 && type == FIELD_TYPE_NUMBER) {
> 		bool is_neg;
> 		if (sql_atoi64(pMem->z,  (int64_t *) &pMem->u.i, &is_neg,
> 			       pMem->n) == 0) {
> 			MemSetTypeFlag(pMem, MEM_Real);
> 			pMem->u.r = pMem->u.i;
> 			return 0;
> 		}
> 		return ! sqlAtoF(pMem->z, &pMem->u.r, pMem->n);
> 	}

Here you use assign 'pMem.u.i' to 'pMem.u.r' without checking
its sign. In theory something like that should work wrong now:

     box.execute("SELECT CAST('9223372036854775837' AS REAL)")

But you need to somehow write that number as blob.

-------------------------
vdbetrace.c:90

Function sqlVdbeExpandSql stringifies integers, but
misses a version for big unsigned.

-------------------------
vdbe.c:307

> 	case FIELD_TYPE_INTEGER:
> 	case FIELD_TYPE_UNSIGNED:
> 		if ((record->flags & MEM_Int) == MEM_Int)
> 			return 0;
> 		if ((record->flags & MEM_UInt) == MEM_UInt)
> 			return 0;
> 		if ((record->flags & MEM_Real) == MEM_Real) {
> 			int64_t i = (int64_t) record->u.r;
> 			if (i == record->u.r)
> 				mem_set_int(record, record->u.r,
> 					    record->u.r <= -1);
> 			return 0;
> 		}

It is a part of function mem_apply_type. When target type is
UNSIGNED, and a value is MEM_Int, you do nothing. Why? Looks like
it is possible to pass here a negative value, and CAST UNSIGNED
would do nothing.





More information about the Tarantool-patches mailing list