Hello,
I am using sqlite3 version 3.11.0. I use the C API.I create a table
"create table device(ieee integer primary key,
                                  name text, 
                                  status integer,
                                  zclversion integer, 
                                  applicationversion integer, 
                                  stackversion integer,
                                  hwversion integer, 
                                  manufacturername text,
                                  modelidentifier text,
                                  datecode text,
                                  endpoint blob);"
Then I insert a record with ieee.
insert into device(ieee) values(12345);
After that I get a table with ieee=12345;
Then I want to add the last blob column.So I write those code.

sqlite3_blob * blob = NULL;
int ret = sqlite3_blob_open(db,
                "main",
                "device",
                "endpoint",
                12345,
                1,
                &blob);
const char* result = sqlite3_errmsg(db->db);
fprintf(stdout, "------------------ %s \n", result);

I got a error when I open the blob.Why? the errmsg is "cannot open value of 
type null I debug the sqlite3 the stack


#0  blobSeekToRow (p=0x812df08, iRow=12345, pzErr=0xbffff314) at 
../sqlite/sqlite3.c:81136
#1  0x080a1cb0 in sqlite3_blob_open (db=0x811d3f8, zDb=0x80f7a90 "main", 
zTable=0x80f7851 "device", zColumn=0x80f7a87 "endpoint", iRow=12345, flags=1, 
ppBlob=0xbffff38c)
#    at ../sqlite/sqlite3.c:81386

rc = sqlite3_step(p->pStmt);                                                    
                                                                                
               x
if( rc==SQLITE_ROW ){                                                           
                                                                                
               x
   VdbeCursor *pC = v->apCsr[0];                                                
                                                                                
                x
   u32 type = pC->aType[p->iCol];                                               
                                                                                
                x
   if( type<12 ){                                                               
                                                                                
                x
     zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",               
                                                                                
                x
         type==0?"null": type==7?"real": "integer"                              
                                                                                
                x
     );                                                                         
                                                                                
                x
     rc = SQLITE_ERROR;                                                         
                                                                                
                x
     sqlite3_finalize(p->pStmt);                                                
                                                                                
                x
     p->pStmt = 0;                                                              
                                                                                
                x
   }else{                                                                       
                                                                                
                x
     p->iOffset = pC->aType[p->iCol + pC->nField];                              
                                                                                
                x
     p->nByte = sqlite3VdbeSerialTypeLen(type);                                 
                                                                                
                x
     p->pCsr =  pC->uc.pCursor;                                                 
                                                                                
                x
     sqlite3BtreeIncrblobCursor(p->pCsr);                                       
                                                                                
                x
   }                                                                            
                                                                                
                x
 }

2016-03-03


zhangkai 

Reply via email to