Closed bradjc closed 8 years ago
Brad, which device are you using this on, or just on your development system? Did you pull the latest changes from November 9th, 2015?
If this is just being run on a standard desktop OS (Linux, Mac, Windows), you can try enabling the error messages in here. It should be enabled by default. Can you tell me what the error message was?
EDIT: I've run your code on my system, and everything went fine/as expected. So I am guessing you are running this on device, which is bad because it probably means there is some sort of memory leak I haven't caught with valgrind/others. Have you modified the LittleD code in any other way? Since I likely won't have your specific device available to me, you will unfortunately need to dig into the code. If the parser is returning NULL on the SELECT parse, then dbparser.c is where you need to look, although that can be daunting without a debugger since there are many cases in which NULL is returned.
I'm testing on Linux.
I think this boils down to a bug in db_op_base_t* parse(char* command, db_query_mm_t* mmp)
stemming from the fact that the array of clausenode
is initialized with an element:
struct clausenode *clausestack = db_qmm_balloc(mmp, sizeof(struct clausenode));
but that item is neither used nor initialized. In my test, it was unfortanutely getting set with a bcode
of 1 (INSERT clause) which was then causing later code to fail because there is obviously no insert in a select *. By adding an init to bcode to make the start of parse look like:
/* Create the clause stack. Top will start at back and move forwards. */
struct clausenode *clausestack_bottom = mmp->last_back;
struct clausenode *clausestack = db_qmm_balloc(mmp,
sizeof(struct clausenode));
struct clausenode *clausestack_top = clausestack;
clausestack->start = -1; /* Used to flag first clause found. */
clausestack->bcode = 0; /* Used to flag first clause found. */
things are working.
I still don't quite understand why there is an extra element at the beginning as it doesn't seem to get used.
OK,
Thanks, thats definitely a problem. Before I simply created a memory allocation spot for a stack (allocated of size 0) and one of the recent changes was to add the item up front to fix a bug during some testing. I obviously didn't turn my brain on and think why I was writing to bad memory in the first place.
I will do some testing and push (properly) fixed code soon.
Sorry that you had to go through the pain in finding that! I've removed the extra allocation and writes completely, all regression tests pass. I've pushed the code up, the issue should now be resolved.
Hello, I tried same example. as it is working for store the data and create the table. but when it is query as "select * from table_name;". it is unable to extract the table information.
Not sure if I'm doing something wrong here but I'm running this code:
and the
select *
returns NULL. If I add another INSERT or remove one INSERT, the SELECT returns correctly.