Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Closed Thread
 
Thread Tools Display Modes
Old Sep 24th, 2009, 9:40 PM   #11
Ancient Dragon
Achieved Level 70

 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 4,345
Rep Power: 10 Ancient Dragon will become famous soon enoughAncient Dragon will become famous soon enough
Re: Sqlite Starter Program

How to link them together will depend on the compiler. What operating system are you using? If its *nix then most likely you are using gnu gcc or g++. If you are using one of MS-Windows operating systems then you could be using one of several different compilers.

You can tell what compiler you are using by paying attention to how you build programs.

BTW: This assumes you already have a basic understanding of C or C++ language. If you don't then you are way over your head in deep water; swim quickly back to shore and learn the language before attempting this.
__________________
PFO's FAQ is here
Forum Rules

There is no cow level (Diablo III)
If you never push yourself you will never improve (Diablo III)
Ancient Dragon is offline  
Old Sep 24th, 2009, 10:28 PM   #12
Arla
Expert Programmer
 
Arla's Avatar
 
Join Date: Mar 2005
Posts: 777
Rep Power: 13 Arla is on a distinguished road
Re: Sqlite Starter Program

Quote:
Originally Posted by Ancient Dragon View Post
BTW: This assumes you already have a basic understanding of C or C++ language. If you don't then you are way over your head in deep water; swim quickly back to shore and learn the language before attempting this.
Pfft, now where is the fun in that

In all seriousness, if it's for Ubuntu I can tell you what packages you'd need to download to run it (from code-blocks), if it's for windows, well, have at it I try hard not to use Doze anymore.
__________________
I can remember, back in '22
They changed the law - came knocking on the door
In that same moment, the broadband seemed to go..
Phones all dead. Gone dizzy in the head..
Arla is offline  
Old Sep 24th, 2009, 11:04 PM   #13
Ancient Dragon
Achieved Level 70

 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 4,345
Rep Power: 10 Ancient Dragon will become famous soon enoughAncient Dragon will become famous soon enough
Re: Sqlite Starter Program

Quote:
Originally Posted by Arla View Post
Pfft, now where is the fun in that

In all seriousness, if it's for Ubuntu I can tell you what packages you'd need to download to run it (from code-blocks), if it's for windows, well, have at it I try hard not to use Doze anymore.
I Windows (Vista). Tried for a week to get Ubuntu or Fadora11 installed, and never could get sound/movies working correctly. Vista works correctly right out of the box, no tweeks or additional packages to install, other than os upgrades.
__________________
PFO's FAQ is here
Forum Rules

There is no cow level (Diablo III)
If you never push yourself you will never improve (Diablo III)
Ancient Dragon is offline  
Old Sep 25th, 2009, 12:10 AM   #14
Arla
Expert Programmer
 
Arla's Avatar
 
Join Date: Mar 2005
Posts: 777
Rep Power: 13 Arla is on a distinguished road
Re: Sqlite Starter Program

Well, have to disagree, I find for everything that Ubuntu does work with, it works really well. Video and Sound never been a problem for me, bluetooth doesn't work great, and the lack of a decent video editor is something that keeps me working with Windows, although I've gone to Windows 7 now since I get a free upgrade when it comes out, while Vista may be fine, there are big parts of it that I just can't/couldn't stand.
__________________
I can remember, back in '22
They changed the law - came knocking on the door
In that same moment, the broadband seemed to go..
Phones all dead. Gone dizzy in the head..
Arla is offline  
Old Sep 25th, 2009, 5:19 AM   #15
Tajn
Newbie
 
Join Date: Sep 2009
Posts: 3
Rep Power: 0 Tajn is on a distinguished road
Re: Sqlite Starter Program

I'm using windows xp
Tajn is offline  
Old Sep 25th, 2009, 2:14 PM   #16
Ancient Dragon
Achieved Level 70

 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 4,345
Rep Power: 10 Ancient Dragon will become famous soon enoughAncient Dragon will become famous soon enough
Re: Sqlite Starter Program

closing this thread because its getting too far off topic, and I am just as guilty as anyone else.
__________________
PFO's FAQ is here
Forum Rules

There is no cow level (Diablo III)
If you never push yourself you will never improve (Diablo III)
Ancient Dragon is offline  
Old Aug 21st, 2010, 10:24 AM   #17
Ancient Dragon
Achieved Level 70

 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 4,345
Rep Power: 10 Ancient Dragon will become famous soon enoughAncient Dragon will become famous soon enough
Re: Sqlite Starter Program

Here is the same program but written in C language
// Before you compile this program you have to 
// dowload the Sqlite source code and header files from 
// http://www.sqlite.org/download.html
// Then you have to compile the sqlite3.c program
// along with this one and link the two object files
// together as a single program.  Or you could compile sqlite3.c
// into a library and link this program with that library.
#include <stdio.h>
#include <string.h>
#include "sqlite3.h"

// Delete this pragma if you are not using
// a Microsoft compiler.
#pragma warning(disable: 4996)

#define DBNAMESIZE 40
// Function prototypes
void fill(sqlite3* db, char* tbname);
void CreateDatabase(sqlite3** db);
void CreateTable(sqlite3* db, char* tbname);
void display(sqlite3* db, char* tbname);


// This is a callback function that is called by Sqlite to process the 
// resultset of a query.  There are other ways to do it without using
// a callback function, such this is the simplest to implemnent.
//
// Parameters are:
//      argc -- the number of rows in the resultset
//      argv[] -- the data for each row
//      azColName -- the name of each column
int callback(void *NotUsed, int argc, char **argv, char **azColName){
  int i;
  for(i=0; i<argc; i++){
    printf("%s = ",azColName[i]);
    if( argv[i] )
        printf(argv[i]);
    else
        printf("NULL");
     printf("\n");
  }
  return 0;
}

// This function just display an error message that
// may have been returned by the various Sqlite functions.
void dsperr(char**db_err)
{
    if( *db_err )
    {
        printf("db_err\n");
        sqlite3_free(*db_err); // release (free) memory
        *db_err = 0; // reinitialize the caller's pointer
    }
}

// This function is called from several places to get 
// the table name.  
void GetTablename(char* tbname)
{
    printf("Enter the table name\n");
    scanf("%s", tbname);
}


int main()
{
    sqlite3* db = 0; // database connection
    char tbname[DBNAMESIZE];   // table name
    int done = 0;
    while(!done)
    {
        char answer[8] = {0};
        printf("\n\nPlease select one of the folowing options\n");
        printf("1. Create a new or open an existing database\n");
        printf("2. Create a new table\n");
        printf("3. Add some data\n");
        printf("4. List all data\n");
        printf("5. Quit\n");
        scanf("%1s",answer);
        switch(answer[0])
        {
            case '1':
                CreateDatabase(&db);
                break;
            case '2':
                CreateTable(db, tbname);
                break;
            case '3':
                fill(db, tbname);
                break;
            case '4':
                display(db, tbname);
                break;
            case '5':
                done = 1;
                break;
        }

    }
    sqlite3_close(db);
}

// Create a new or open an existing database.
// If the database does not exist it will be
// created.  Note that you can specif the full
// path and filename which may, or may not, contain spaces.
void CreateDatabase(sqlite3** db)
{
    char dbname[DBNAMESIZE];
    int n;
    printf("Please enter the name of the database\n");
    fgets(dbname,sizeof(dbname), stdin);
    if( dbname[strlen(dbname)-1] == '\n')
        dbname[strlen(dbname)-1] = '\0';
    n = sqlite3_open(dbname, db);
    if( n != SQLITE_OK )
    {
        printf("Error opening database.\n");
    }
    else
        printf("Database open ok\n");
}

// Add a new table to the database.  If the table
// name already exists then an error message will be
// displayed.
void CreateTable(sqlite3* db, char* tbname)
{
    char* db_err = 0;
    int n = 0;
    char statement[255] = {0};
    GetTablename(tbname);
    if( tbname[0] == '\0' )
        return;
    sprintf(statement, "CREATE TABLE %s (id integer);", tbname);

    n = sqlite3_exec(db, statement, NULL, 0, &db_err);
    dsperr(&db_err);
    if( n != SQLITE_OK )
    {
        printf("Error executing \"%s\"\n",statement);
    }
    else
        printf("Table created successfully\n");

}


// Just dump some data into the table.  You don't
// have a choice of the kind or quantity of data to be entered.
//
void fill(sqlite3* db, char* tbname)
{
    char* db_err = 0;
    int i = 0;
    int n = 0;
    char buf[80];
    if( strlen(tbname) == 0)
    {
        GetTablename(tbname);
        if( tbname[0] == '\0')
            return;
    }
    for(i = 1; i < 100; i++)
    {
        sprintf(buf,"insert into %s values(%d);", tbname, i);
        n = sqlite3_exec(db, buf, NULL, 0, &db_err);
        dsperr(&db_err);
        if( n != SQLITE_OK )
        {
            printf("Error inserting value %d\n", i);
            break;
        }
    }

}

// Query the database for all the data in the table and
// display it in the callback function.  
void display(sqlite3* db, char* tbname)
{
    char* db_err = 0;
    char select[255] = {0};
    if( strlen(tbname) == 0)
    {
        GetTablename(tbname);
        if( tbname[0] == '\0' )
            return;
    }
    if( strlen(tbname) > 0)
    {
        sprintf(select, "select * from %s;", tbname);
        sqlite3_exec(db, select, callback, 0, &db_err);
        dsperr(&db_err);
    }

}
__________________
PFO's FAQ is here
Forum Rules

There is no cow level (Diablo III)
If you never push yourself you will never improve (Diablo III)
Ancient Dragon is offline  
Closed Thread

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with input of a program. lrh9 C++ 7 May 29th, 2009 1:36 AM
Will pay for LC-3 assembly language program help lilfindley Paid Job Offers 0 Mar 17th, 2009 11:24 PM
Language display in program Prm753 C++ 3 May 30th, 2006 6:45 PM
Creating a program to test a program sixstringartist C 8 Jan 21st, 2006 2:15 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:55 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC