Magic numbers on sqlite source code

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Magic numbers on sqlite source code

Domingo Alvarez Duarte
Hello Richard !

Time to time I look at some commits that call my attention like this:

[e47fdb49] <> Leaf:
Refactor the fts3ColumnMethod() function so that all branches can be
covered. (user: dan
tags: trunk

And I can see that there is a usage of magic numbers instead of an enum
on named macro, this at large makes understanding of the source a bit

Some comments following the magic number could be removed if instead of
magic numbers a named constant was used, with the benefit that a named
constant can be searched to see all places where it is used.


switch( iCol-p->nColumn ){
case 0: //>>>>>>>>>>>>>> Instead of '0' a named constant would make
following the code a bit easier
/* The special 'table-name' column */
sqlite3_result_blob(pCtx, &pCsr, sizeof(Fts3Cursor*), SQLITE_TRANSIENT);
sqlite3_result_subtype(pCtx, SQLITE_BLOB);

case 1:  //>>>>>>>>>>>>> Magic number
/* The docid column */
sqlite3_result_int64(pCtx, pCsr->iPrevId);

case 2:  // >>>>>>>>>>> Magic number
if( pCsr->pExpr ){
sqlite3_result_int64(pCtx, pCsr->iLangid);
}else if( p->zLanguageid==0 ){
sqlite3_result_int(pCtx, 0);
iCol = p->nColumn;
/* fall-through */

/* A user column. Or, if this is a full-table scan, possibly the
** language-id column. Seek the cursor. */
rc = fts3CursorSeek(0, pCsr);
if( rc==SQLITE_OK && sqlite3_data_count(pCsr->pStmt)-1>iCol ){
sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1));

Cheers !

sqlite-users mailing list
[hidden email]