LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-08-2011, 05:35 AM   #1
golden_boy615
Member
 
Registered: Dec 2008
Distribution: Ubuntu Fedora
Posts: 445

Rep: Reputation: 17
can not create sqlite table with C API


hello
I am new in sqlite and this is my C code :


Code:
#include <stdio.h>
#include <sqlite3.h>
#include <string.h>


int main()
{
 sqlite3 *db;
 sqlite3_stmt *stmt;
 char *sqlitequery="create table ee (row INTEGER PRIMARY KEY,a INTEGER);";
 int rc = 0;

   rc = sqlite3_open("ehsan.db", &db);
   if( rc )
   {
     fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
   }
   else
   {
     rc = sqlite3_prepare_v2(db, sqlitequery, strlen(sqlitequery), &stmt, 0);
     printf("return value %d:",rc);
     if( rc )
     {
       fprintf(stderr, "SQL error: %d : %s\n", rc, sqlite3_errmsg(db));
     }
 }
 return 0;
}
this code makes database file for me but it does not create its table named "ee" into it.
what is wrong with it?
 
Old 10-08-2011, 11:48 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Two things I see off the bat:

1. You should pass a length of "strlen (sqlitequery)+1"
<= Don't forget space for the "null" terminator

2. I don't see where you're executing the statement you've prepared (e.g. "sqlite3_step()")

Q: Have you considered substituting "sqlite3_exec()"?

Q: What was the sample output? Any errors or warnings?

Here's a nice, short tutorial:

http://www.yolinux.com/TUTORIALS/SQLite.html
 
Old 10-08-2011, 05:08 PM   #3
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by paulsm4 View Post
1. You should pass a length of "strlen (sqlitequery)+1"
<= Don't forget space for the "null" terminator
You're not wrong, but it's not essential in this case
Quote:
When nByte is non-negative, the zSql string ends at either the first '\000' or '\u0000' character or the nByte-th byte, whichever comes first. If the caller knows that the supplied string is nul-terminated, then there is a small performance advantage to be gained by passing an nByte parameter that is equal to the number of bytes in the input string including the nul-terminator bytes.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How To Create Remote API Scripts For ISPConfig 3 LXer Syndicated Linux News 0 05-06-2011 04:40 PM
LXer: Sqlite-Commander - A ncurses based tool to display the records and tables of a sqlite database LXer Syndicated Linux News 0 01-02-2011 09:11 AM
How to read the start address of the ACPI table ? are there any kernel API? jitendrapradhan Linux - Kernel 0 10-08-2008 04:24 AM
function or api to create account ssonnagi Linux - General 2 02-07-2006 04:57 AM
route table lookup Kernel API ?? Nalin Gupta Programming 0 07-01-2004 04:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration