SQLite3 with C

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

SQLite3 with C

Ricardo Lima
I built a straightforward program in C. It's just a STACK structure (first in, last out) that takes input from the user and stores it into the stack. After I close the program, all the data vanishes since I don't have a database implemented into the program. Even so, the program runs fine. It allocates memory according to the user's input, and I always validate every allocation.

In fact, my issue isn't concerning C code itself. It's the implementation of SQLite into the C code. Every stack_node has a value (integer), date (char), and info (char). The wallet structure is the "middle-man" between the stack_node and the DB, and it has the same attributes plus an ID (integer autoincremented). What I'm trying to do is to as soon as the user inputs data (while the program is running) this data gets stored not only in the stack but also in the DB. After the user is done inputting data, I usually use pop_stack() to retrieve the data from the stack onto the screen, but since the data is stored in the DB, it makes more sense just to extract all data from the DB.

I don't get any compilation errors and the SQLite source files/header files are implemented correctly into the code. I know this because I'm using SQLite Studio ( SQLite GUI) and I see all the attributes from the wallet DB, but they are all empty.
So, that's my issue. I'm doing something wrong that causes the program to not store the data correctly into the DB.

--- Is it a waste of memory and running time for the program to create a stack, stack_node etc...to only after all that store the information in the DB? Should I just skip all that and program just for the DB? If so, how would I do that since I would eventually run into the same problem. I'm using the stack because I might have more control over what I can do with the data like adding the values, calculate average expenditure and so on.



Thank you so much!

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

main.c (8K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: SQLite3 with C

Simon Slavin-3
On 15 Aug 2018, at 6:26am, Ricardo Lima <[hidden email]> wrote:

> I don't get any compilation errors and the SQLite source files/header files are implemented correctly into the code. I know this because I'm using SQLite Studio ( SQLite GUI) and I see all the attributes from the wallet DB, but they are all empty.

Please use the SQLite shell tool (download from the SQLite site as "Precompiled Binaries") rather than SQLite Studio.

When making SQLite API calls, are you checking the result codes ?  Result codes from those calls should be SQLITE_OK to indicated successful completion.  If you are getting any other value, post it and we'll figure out what's wrong.

Are you using sqlite3_exec() or _prepare(),_step(),_finalize() ?

Are you closing the database file before your application quits ?

Simon.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: SQLite3 with C

Simon Davies
In reply to this post by Ricardo Lima
Hi Ricardo,

On 15 August 2018 at 06:26, Ricardo Lima <[hidden email]> wrote:
> I built a straightforward program in C. It's just a STACK structure (first in, last out) that takes input from the user and stores it into the stack. After I close the program, all the data vanishes since I don't have a database implemented into the program. Even so, the program runs fine. It allocates memory according to the user's input, and I always validate every allocation.
>
> In fact, my issue isn't concerning C code itself. It's the implementation of SQLite into the C code. Every stack_node has a value (integer), date (char), and info (char). The wallet structure is the "middle-man" between the stack_node and the DB, and it has the same attributes plus an ID (integer autoincremented). What I'm trying to do is to as soon as the user inputs data (while the program is running) this data gets stored not only in the stack but also in the DB. After the user is done inputting data, I usually use pop_stack() to retrieve the data from the stack onto the screen, but since the data is stored in the DB, it makes more sense just to extract all data from the DB.
>
> I don't get any compilation errors and the SQLite source files/header files are implemented correctly into the code. I know this because I'm using SQLite Studio ( SQLite GUI) and I see all the attributes from the wallet DB, but they are all empty.
> So, that's my issue. I'm doing something wrong that causes the program to not store the data correctly into the DB.

in
        if( push_stack( s, value, date, info ) ){
                addData( db, node );
         }

node is always NULL, and addData checks for that, and does nothing...

> --- Is it a waste of memory and running time for the program to create a stack, stack_node etc...to only after all that store the information in the DB? Should I just skip all that and program just for the DB? If so, how would I do that since I would eventually run into the same problem. I'm using the stack because I might have more control over what I can do with the data like adding the values, calculate average expenditure and so on.
>
> Thank you so much!

Regards,
Simon
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users