[sqlite] sqlite3_free_table question

2006-06-29 Thread Richard Boyd

Hi again,

I now check for NULL to be sure that I'm trying to free up a pointer that
actually points to something. Is there an easy way for me to ensure that the
memory has been successfully freed up? I understand this might be a basic C
question rather than a specific Sqlite question, so apologies for that...

Thanks again,
Richard.

-Original Message-
From: Dennis Cote [mailto:[EMAIL PROTECTED] 
Sent: 28 June 2006 21:46
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] sqlite3_free_table question

Richard Boyd wrote:
> Basically I have a structure I use to hold data results:
>
> //=
> typedef struct {
>   char   *sqlStatement; // Either the sqlstatement to be executed or the
> last statement that was executed
>   char   **results; // the result stored in an array
>   char   *err_msg;  // the error message
>   intnumrows;   // number of rows of results
>   intnumcols;   // the number of columns of data returned
> } RESULT_T;
> //===
>
> I pass this structure to a wrapper function that ultimately calls
> sqlite3_get_table and returns the results structure on tresults
>
> //===
> int execute_command (size_t   nbytes,  char *command,   RESULT_T
> *tresults)
> //===
>
> In the function that calls execute_command(), I want to free up the memory
> that was allocated by sqlite3_get_table().
>
> Do I just call the free function like this:
> sqlite3_free_table(tresults.results); (assuming that I created a variable
> called 'tresults' of type RESULT_T in the calling function).
>
> Also, how do I free up the error messages? What if there are no results
> returned by sqlite3_get_table, can I still attempt to free up the memory
> with 'sqlite3_free_table'
>
> I appreciate you reading down this far, and sorry if my code snips are
hard
> to follow!!
>
>   
Richard,

Your call to sqlite3_free_table is correct.

You free the error message by calling sqlite3_free(tresult.err_msg).

If either pointer returned by sqlite3_get_table() is NULL, then no 
memory was allocated, so there is no need to free it, however I believe 
it should be safe to call the free routines with a NULL pointer.

HTH
Dennis Cote



-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.9.6/378 - Release Date: 28/06/2006




RE: [sqlite] sqlite3_free_table question

2006-06-28 Thread Richard Boyd
Dennis,

Ok thanks for the quick response. I'll persevere with that then and get back
if I still have problems.

Thanks,
Richard. 





[sqlite] sqlite3_free_table question

2006-06-28 Thread Richard Boyd
Hi all,

Firstly, forgive me for a slightly naïve question; I don’t normally code in
C and I’m having problems freeing up memory.

Basically I have a structure I use to hold data results:

//=
typedef struct {
  char   *sqlStatement; // Either the sqlstatement to be executed or the
last statement that was executed
  char   **results; // the result stored in an array
  char   *err_msg;  // the error message
  intnumrows;   // number of rows of results
  intnumcols;   // the number of columns of data returned
} RESULT_T;
//===

I pass this structure to a wrapper function that ultimately calls
sqlite3_get_table and returns the results structure on tresults

//===
int execute_command (size_t   nbytes,  char *command,   RESULT_T
*tresults)
//===

In the function that calls execute_command(), I want to free up the memory
that was allocated by sqlite3_get_table().

Do I just call the free function like this:
sqlite3_free_table(tresults.results); (assuming that I created a variable
called ‘tresults’ of type RESULT_T in the calling function).

I’ve tried quite a few permutations and am never quite sure if I’ve actually
freed up the memory. Is there a fool proof way to check?

Also, how do I free up the error messages? What if there are no results
returned by sqlite3_get_table, can I still attempt to free up the memory
with ‘sqlite3_free_table’

I appreciate you reading down this far, and sorry if my code snips are hard
to follow!!

TIA
Richard.



[sqlite] sqlite3 dll for C#

2005-12-07 Thread Richard Boyd
Hi,
 
I managed to find a dll for sqlite2 that will work with C#. Has anyone any
idea where I can find a dll for sqlite3?
 
Thanks,
R.


RE: [sqlite] quotes around text in returned data?

2005-11-03 Thread Richard Boyd

Thanks all!

I'll give those a go.

-Richard.



RE: [sqlite] quotes around text in returned data?

2005-11-03 Thread Richard Boyd


>>Use the built-in quote() function.
--

Ok I think I found it. (http://www.sqlite.org/lang_expr.html)
I'm not really familiar with this method of calling a function in an
expression. Is there away to have it only quote the TEXT columns and not the
INTEGER columns, or does it do this anyway by default?

Ideally I'd like the entire row returned with TEXT strings in quotes but
everything else left as normal.

SELECT * from Table0 quote(??some expression in here??);


Sorry, I'm a bit lost.  Are there any code snippets on the usage?

Thanks again.
R.





RE: [sqlite] quotes around text in returned data?

2005-11-03 Thread Richard Boyd

>>Use the built-in quote() function.
--

Just what I'm after (huge sigh of relief) Is it sqlite3_quote?

I had a search through the documentation and didn't come up with anything.
Obviously I didn't look hard enough. I'll go back and look again.

Thanks very much for the quick response and apologies if this is a common
question.
R.



[sqlite] quotes around text in returned data?

2005-11-03 Thread Richard Boyd

Hi,

Is there anyway to get Sqlite to add 'quotes' around text strings when it is
returning data from a select command?

For example:

I have a table called table0 which is created using
CREATE TABLE table0 (col1 INTEGER, col2 TEXT, col3 INTEGER);

I have a row in the table
1|this is a text string|2

Now to insert that I need something like:
INSERT INTO table0 values(1,'this is a text string',2);

When I go to retrieve this data using
SELECT * from table0;
I get:
1|this is a text string|2
Which I suppose is correct. But what happens if I want to put this row into
another table???  I need to parse it and add in the quotes (' ') around the
text string??

The problem I have is that I retrieve data from a remote database then pass
over a network to be received and placed into a local table. OF course I get
an error because Sqlite complains about the string.

Can anyone help with this problem???

Thanks in advance.
R.




RE: [sqlite] Function to find the size returned data size from a SELECT??

2005-09-22 Thread Richard Boyd

OK Thanks for your reply. Yeah, I know that sqlite3_get_table() allocates
the memory for me, but thanks for the heads up any way!

I think the possibility of checking the number of rows will be sufficient
for my purposes...

If I don't check is there not a possibility of there not being enough memory
to fit the returned data? I guess Sqlite checks for this when doing the
malloc? Is there a specific error returned when this is the case (i.e. it
runs out of memory)? It's hardly likely to happen but I need to handle the
case none the less...

Thanks again,
Richard.


> I was wondering if there was a way to find the size of data that will be
> returned before actually making the call to sqlite3_get_table which will
> return a pointer to a malloc'd memory location. My question is really: can
I
> find the required memory size before the call?

The short answer is no, not without executing a "SELECT count() ..."
statement to figure out how many rows will be returned by your statement.

Sanity check: You know that sqlite3_get_table() allocates the memory 
for you, right (which you then free later using sqlite3_free_table())? You 
don't have to supply your own malloc'd blob.





[sqlite] Function to find the size returned data size from a SELECT??

2005-09-21 Thread Richard Boyd
Hi,
 
I was wondering if there was a way to find the size of data that will be
returned before actually making the call to sqlite3_get_table which will
return a pointer to a malloc'd memory location. My question is really: can I
find the required memory size before the call?
 
Thanks in advance,
Richard.
 


RE: [sqlite] correct use of sqlite3_get_table

2005-03-03 Thread Richard Boyd
Ok thanks for responding...

That was my understanding but I was wondering why it only returned 1 Row in
*pnRow. I've figured it out now (I think). The first row contains the column
name but does not count as a result. Hence the 1 row that is referred to in
*pnRow returned from sqlite3_get_table() is the single result I'm after.

Lo and behold, when I check the 2nd string referenced by the result pointer,
I get what I'm after!

Many thanks!
Richard.

-Original Message-
From: Dennis Cote [mailto:[EMAIL PROTECTED] 
Sent: 03 March 2005 19:31
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] correct use of sqlite3_get_table

Richard Boyd wrote:

> Hi all,
>
> I’m trying to use sqlite3_get_table() to execute SQL commands on a 
> database. I’ve included a code snippet below.
>
> The problem I’m having is that when I execute the "SELECT 
> MAX(time_stamp) FROM table32;” command using sqlite3_get_table() I 
> only get one column and 1 row returned and the result contains 
> “MAX(time_stamp)” rather than the value I’m after. When I run the same 
> command in sqlite3.exe shell I get the desired result (a single number).
>
> Any one any ideas where I’m going wrong with this??
>
Richard,

You need to read the documentation for the sqlite3_get_table() function 
at http://www.sqlite.org/capi3ref.html#sqlite3_get_table. It explains 
how the column header information is returned along with the actual 
data. You are looking at the heading for your column, the data is 
further into the results array.

HTH
Dennis Cote


-- 
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.5.2 - Release Date: 28/02/2005




--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.5.2 - Release Date: 28/02/2005



[sqlite] correct use of sqlite3_get_table

2005-03-02 Thread Richard Boyd








Hi all,

 

I’m trying to use sqlite3_get_table() to execute SQL commands on a database. I’ve
included a code snippet below. 

 

The problem I’m having is that when I execute
the "SELECT MAX(time_stamp)
FROM table32;” command using sqlite3_get_table() I only get one column
and 1 row returned and the result contains “MAX(time_stamp)”
rather than the value I’m after. When I run the same command in
sqlite3.exe shell I get the desired result (a single number). 

 

Any one any ideas where I’m going wrong with
this??

 

TIA

-Richard.

 



 

rc
= sqlite3_open("testdb", &db);

  if( rc )

  {

    fprintf(stderr, "Can't open database: %s\n",
sqlite3_errmsg(db));

   
sqlite3_close(db);

    exit(1);

  }

 

  printf ("about to execute the
rxd command\n");

  printf ("%s\n",
command);

  rc = sqlite3_get_table(db,

 "SELECT MAX(time_stamp) FROM
table32;",//command,

 &tresults->results,  //&zResult,

 &tresults->numrows,  //&numrows,

 &tresults->numcols,  //&numcols,

 &tresults->err_msg); //&zErrMsg);

 



 






No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.5.2 - Release Date: 28/02/2005


RE: [sqlite] Best way to check for existence of a table?

Thanks for the prompt reply...

I tried what you suggested and I always get the error message:
"SQL error: no such column: table32"
Whether the table exists or not, I always get returned value of 1 from
sqlite3_exec().

The exact command that I use is:
SELECT count(*) FROM sqlite_master WHERE name=table32 AND type='table';

I also tried single quotes around the table32 name:
SELECT count(*) FROM sqlite_master WHERE name='table32' AND type='table';
And get no errors whether the table exists or not

When I try the other method suggested ("SELECT NULL FROM sqlite_master WHERE
tbl_name = 'your-table';") I don’t get any error messages whether the table
exists or not. The return value is always 0.

I'm obviously missing where the error is being flagged, have you any more
pointers?
Sorry if I'm being dense here but I'm new to SQL databases.

Thanks again,
Richard.



-Original Message-
From: D. Richard Hipp [mailto:[EMAIL PROTECTED] 
Sent: 13 February 2005 23:46
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] Best way to check for existence of a table?

On Sun, 2005-02-13 at 22:58 +, Richard Boyd wrote:
>  
> 
> I need a way to check if a table exists from some C code. 

SELECT count(*) FROM sqlite_master WHERE
  name= AND type='table';
-- 
D. Richard Hipp <[EMAIL PROTECTED]>



-- 
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 10/02/2005




--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 10/02/2005



[sqlite] Best way to check for existence of a table?









Hi,

 

I need a way to check if a table exists from some C
code. I wrote some code to try to select a row from a table and then checked
the error result. However, the error code is always ‘1’ (which is just
a general SQLITE_ERROR) if the table does not exist. Is there any way I can
differentiate between the error code meaning ‘no table found’ and
other errors?? Or is there a neater way to check for existence of a table?

 

TIA,

Richard.






No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 10/02/2005


[sqlite] basic sql question: Is there a way of entering multiple rows in a table?









Hi,

 

I know I can create a temporary table and insert them
from that or use a for loop in C and get it to update
the table one row at a time, but is there a ‘nicer’ way??

 

 I basically have
a string of text which I’ve obtained from another (remote) Sqlite database
which I want to append to the end of an existing table in a separate database.
Is there a better way than doing it one row at a time?

 

TIA,

Richard.






No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 10/02/2005


[sqlite] Accesing database remotely









Hi,

 

I’m writing a database that will be accessed remotely
over Ethernet. I had started to write a protocol that would float on top of
TCP/IP but after reading some posts here it seems that it would be overkill. Is
it practical to access the database file remotely and run commands on it from
the remote PC? Are there going to be problems with sharing conflicts with more
than one application accessing the database simultaneously? I know from reading
some Sqlite documentation that there is some protection built into Sqlite. Does
it work automatically or is there something I’d have to do at the
operating system level?

 

FYI: I’m using Linux for the computer where the
database is stored and windows for the machine that will remotely access the
database over Ethernet.

 

Thanks again,

Richard.






No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.1 - Release Date: 27/01/2005


RE: [sqlite] joining a table to the end of another table

Many thanks for the replies.

I knew it must be something simple!!

Cheers,
R.

-Original Message-
From: John LeSueur [mailto:[EMAIL PROTECTED] 
Sent: 31 January 2005 21:27
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] joining a table to the end of another table

Richard Boyd wrote:

> Hi,
>
> I’m inexperienced with databases so forgive me if this is a silly 
> question.
>
> What I want to do is join to separate tables together into one table. 
> This is to enable me to synchronize databases held on remote systems. 
> I would use a master table which would have the dates of each update 
> and then I could see which databases need updated so that they all the 
> same.
>
> Every time I add data to the main database I put it in a new table, 
> with exactly the same structure as its predecessors. Then updating is 
> a simple matter of checking to see which tables I have on the remote 
> machine and then copying across the tables which are not there. My 
> problem is I’m unclear how to link multiple tables sequentially. I’ve 
> looked into joins but they seem to be a way of performing relational 
> searches which is not what I’m after.
>
> See example below if it’s not clear what I’m looking to do:
>
> Table 0 Table1
>
> 0 | A 5 | F
>
> 1 | B 6 | G
>
> 2 | C 7 | H
>
> 3 | D
>
> 4 | E
>
> Combined table
>
> 0 | A
>
> 1 | B
>
> 2 | C
>
> 3 | D
>
> 4 | E
>
> 5 | F
>
> 6 | G
>
> 7 | H
>
> I’m sure there’s a simple way to do it but I’m not sure how.
>
> Thanks in advance…
>
> Richard
>
>
>
>No virus found in this outgoing message.
>Checked by AVG Anti-Virus.
>Version: 7.0.300 / Virus Database: 265.8.1 - Release Date: 27/01/2005
>  
>
insert into combined_table
select * from table0
union
select * from table1

John


-- 
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.1 - Release Date: 27/01/2005




--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.1 - Release Date: 27/01/2005



[sqlite] joining a table to the end of another table









Hi, 

 

I’m inexperienced with databases so forgive me if this
is a silly question.

 

What I want to do is join to separate tables together into
one table. This is to enable me to synchronize databases held on remote systems.
I would use a master table which would have the dates of each update and then I
could see which databases need updated so that they all the same.

 

Every time I add data to the main database I put it in a new
table, with exactly the same structure as its predecessors. Then updating is a
simple matter of checking to see which tables I have on the remote machine and
then copying across the tables which are not there. My problem is I’m
unclear how to link multiple tables sequentially. I’ve looked into joins
but they seem to be a way of performing relational searches which is not what I’m
after.

 

See example below if it’s not clear what I’m
looking to do:

 

Table 0  Table1

0 | A 5
| F

1 | B 6
| G

2 | C 7
| H

3 | D

4 | E

 

Combined table

0 | A

1 | B

2 | C

3 | D

4 | E

5 | F

6 | G

7 | H

 

I’m sure there’s a simple way to do it but I’m
not sure how.

 

Thanks in advance…

Richard

 

 






No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.1 - Release Date: 27/01/2005


RE: [sqlite] synchronising two databases

Thanks,

I'll look into something like that. I think there must be a neat way of
doing this synchronisation besides actually copying files, but this method
should get me started.

I'll keep you posted if I come up with any other method.

Regards,
Richard.

-Original Message-
From: Andrew Piskorski [mailto:[EMAIL PROTECTED]
Sent: 13 December 2004 14:24
To: [EMAIL PROTECTED]
Subject: Re: [sqlite] synchronising two databases


On Mon, Dec 13, 2004 at 02:00:05PM -0000, Richard Boyd wrote:

> My question is this: Is it possible for me to copy across the database
file
> and then append it to the end of the locally held database thus
> synchronizing the two? Is there a better way to do this synchronization?

If both databases are shut down, presumably you could use rsync to
blindly synchronize the two at the binary level.  Conceivably you
could even integrate something like librsync into SQLite and thus do
the rsync operation while the database is locked, with no other
activity going on.

  http://librsync.sourceforge.net/

(This is all speculation on my part though, I have tried nothing of
the sort.  And of course, there might already be some better way to do
it in SQLite.)

--
Andrew Piskorski <[EMAIL PROTECTED]>
http://www.piskorski.com/
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.801 / Virus Database: 544 - Release Date: 24/11/04

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.813 / Virus Database: 553 - Release Date: 13/12/04



[sqlite] synchronising two databases

Hi all,

I have an application where I need to access a database remotely (using
TCP/IP). I had thought of just calling sqlite commands (possibly using RPC)
and getting database data returned. However, as I will only periodically
access the remote database, I need to effectively keep a copy of the
database locally for offline number crunching.

My question is this: Is it possible for me to copy across the database file
and then append it to the end of the locally held database thus
synchronizing the two? Is there a better way to do this synchronization?

Many thanks in advance,
Richard


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.801 / Virus Database: 544 - Release Date: 24/11/04


[sqlite] example for TCP connection to sqlite database.

Hi,

This is sort of a vague question so apologies in advance..

I need a simple way to connect to an sqlite database remotely using tcp
(over IP). I've had a look at some offerings on the web such as sql relay
(http://sqlrelay.sourceforge.net/). This is very comprehensive but seems to
be a bit too sophisticated for my application and seems to require a fair
amount of setup. I was wondering if anyone had any pointers for a simple
client server that I could use to request data from databases remotely.

Thanks in advance.

Richard.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.801 / Virus Database: 544 - Release Date: 24/11/04



RE: [sqlite] cross compiling for Linux running on an ARM

>
>hi,
>
>i had best results with the pre processed version of sqlite. this was
>with version 2.8. i haven't tried version 3 of sqlite yet.
>i compiled it under uclinux.
>
>greets, peter
>
>Richard Boyd wrote:
>> I'm trying to run sqlite on Linux running on an embedded ARM processor on
a
>> development board.

Thanks all for your replies.

Peter,

Have you a sample makefile which I could use as a starting point for this.

Thanks again,
Richard.




[sqlite] cross compiling for Linux running on an ARM

Hi,

I'm trying to run sqlite on Linux running on an embedded ARM processor on a
development board. I'm using Linux (running on a PC) as my development
environment. What is the simplest way to approach this? Can I modify the
configuration files supplied in the build to do this or should I start from
the pre-generated files that came in the 'sqlite-source-3_0_8.zip'. I've not
had much luck with either approach yet I'm afraid.

Thanks in advance,
Richard.