How do I attach a database from C++?

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

How do I attach a database from C++?

Greg Stark-4
I'm having difficulty attaching a database from C++.

Within my code, I'm using an sqlite3_prepare call:

         prepareResult = pSqlBundle->sqlite3_prepare (db_, "ATTACH  
DATABASE 'window_5.sdb' AS W5;", -1, &attachSqlStmt, &tailOfSqlStmt);

but it returns an error (i.e., prepareResult comes back as  
SQLITE_ERROR).

Just to make sure that there were no problems with the databases or  
my syntax, I tried the attach command (i.e., ATTACH DATABASE  
'window_5.sdb' AS W5;) from the command line, and everything worked  
fine.  I tried using the full path name for the database-filename,  
but that didn't work either.

I'm sure it's something simple, but what I'm I doing wrong?

Thanks,
Greg
Reply | Threaded
Open this post in threaded view
|

RE: How do I attach a database from C++?

Thomas Briggs

   I think that the semi-colon at the end of the statement is what's
causing your problem.  The command shell requires the semi-colon to mark
the end of a statement; in code, your statement ends at the end of the
string.

   -Tom

> -----Original Message-----
> From: Greg Stark [mailto:[hidden email]]
> Sent: Thursday, August 18, 2005 7:38 PM
> To: [hidden email]
> Subject: [sqlite] How do I attach a database from C++?
>
> I'm having difficulty attaching a database from C++.
>
> Within my code, I'm using an sqlite3_prepare call:
>
>          prepareResult = pSqlBundle->sqlite3_prepare (db_, "ATTACH  
> DATABASE 'window_5.sdb' AS W5;", -1, &attachSqlStmt, &tailOfSqlStmt);
>
> but it returns an error (i.e., prepareResult comes back as  
> SQLITE_ERROR).
>
> Just to make sure that there were no problems with the databases or  
> my syntax, I tried the attach command (i.e., ATTACH DATABASE  
> 'window_5.sdb' AS W5;) from the command line, and everything worked  
> fine.  I tried using the full path name for the database-filename,  
> but that didn't work either.
>
> I'm sure it's something simple, but what I'm I doing wrong?
>
> Thanks,
> Greg
>
Reply | Threaded
Open this post in threaded view
|

Re: How do I attach a database from C++?

Greg Stark-4
Tom,

I appreciate you're help but I'm pretty sure that the semicolon has  
to be there (well. at least it's required in all the other statements  
I've written to date -- this one statement is part of a much large  
program that's working fine other than for this one ATTACH).

My guess is that SQLite3 doesn't know where to find my database, but  
I'm not sure how to tell it where to look.

-Greg

On Aug 19, 2005, at 6:07 AM, Thomas Briggs wrote:

>
>    I think that the semi-colon at the end of the statement is what's
> causing your problem.  The command shell requires the semi-colon to  
> mark
> the end of a statement; in code, your statement ends at the end of the
> string.
>
>    -Tom
>
>
>> -----Original Message-----
>> From: Greg Stark [mailto:[hidden email]]
>> Sent: Thursday, August 18, 2005 7:38 PM
>> To: [hidden email]
>> Subject: [sqlite] How do I attach a database from C++?
>>
>> I'm having difficulty attaching a database from C++.
>>
>> Within my code, I'm using an sqlite3_prepare call:
>>
>>          prepareResult = pSqlBundle->sqlite3_prepare (db_, "ATTACH
>> DATABASE 'window_5.sdb' AS W5;", -1, &attachSqlStmt, &tailOfSqlStmt);
>>
>> but it returns an error (i.e., prepareResult comes back as
>> SQLITE_ERROR).
>>
>> Just to make sure that there were no problems with the databases or
>> my syntax, I tried the attach command (i.e., ATTACH DATABASE
>> 'window_5.sdb' AS W5;) from the command line, and everything worked
>> fine.  I tried using the full path name for the database-filename,
>> but that didn't work either.
>>
>> I'm sure it's something simple, but what I'm I doing wrong?
>>
>> Thanks,
>> Greg
>>
>>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: How do I attach a database from C++?

Puneet Kishor
Greg Stark wrote:
> Tom,
>
> I appreciate you're help but I'm pretty sure that the semicolon has  to
> be there (well. at least it's required in all the other statements  I've
> written to date -- this one statement is part of a much large  program
> that's working fine other than for this one ATTACH).
>
> My guess is that SQLite3 doesn't know where to find my database, but  
> I'm not sure how to tell it where to look.

well, have you tried giving it the full path name to the database?


>
> -Greg
>
> On Aug 19, 2005, at 6:07 AM, Thomas Briggs wrote:
>
>>
>>    I think that the semi-colon at the end of the statement is what's
>> causing your problem.  The command shell requires the semi-colon to  mark
>> the end of a statement; in code, your statement ends at the end of the
>> string.
>>
>>    -Tom
>>
>>
>>> -----Original Message-----
>>> From: Greg Stark [mailto:[hidden email]]
>>> Sent: Thursday, August 18, 2005 7:38 PM
>>> To: [hidden email]
>>> Subject: [sqlite] How do I attach a database from C++?
>>>
>>> I'm having difficulty attaching a database from C++.
>>>
>>> Within my code, I'm using an sqlite3_prepare call:
>>>
>>>          prepareResult = pSqlBundle->sqlite3_prepare (db_, "ATTACH
>>> DATABASE 'window_5.sdb' AS W5;", -1, &attachSqlStmt, &tailOfSqlStmt);
>>>
>>> but it returns an error (i.e., prepareResult comes back as
>>> SQLITE_ERROR).
>>>
>>> Just to make sure that there were no problems with the databases or
>>> my syntax, I tried the attach command (i.e., ATTACH DATABASE
>>> 'window_5.sdb' AS W5;) from the command line, and everything worked
>>> fine.  I tried using the full path name for the database-filename,
>>> but that didn't work either.
>>>
>>> I'm sure it's something simple, but what I'm I doing wrong?
>>>
>>> Thanks,
>>> Greg
>>>
>>>
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: How do I attach a database from C++?

Greg Stark-4

On Aug 19, 2005, at 9:37 AM, Puneet Kishor wrote:

> Greg Stark wrote:
>
>> Tom,
>> I appreciate your help but I'm pretty sure that the semicolon has  
>> to be there (well, at least it's required in all the other  
>> statements  I've written to date -- this one statement is part of  
>> a much larger  program that's working fine other than for this one  
>> ATTACH).
>> My guess is that SQLite3 doesn't know where to find my database,  
>> but  I'm not sure how to tell it where to look.
>>
>
> well, have you tried giving it the full path name to the database?

I've tried the full path name, too -- no luck there either...

>
>> -Greg
>> On Aug 19, 2005, at 6:07 AM, Thomas Briggs wrote:
>>
>>>
>>>    I think that the semi-colon at the end of the statement is what's
>>> causing your problem.  The command shell requires the semi-colon  
>>> to  mark
>>> the end of a statement; in code, your statement ends at the end  
>>> of the
>>> string.
>>>
>>>    -Tom
>>>
>>>
>>>
>>>> -----Original Message-----
>>>> From: Greg Stark [mailto:[hidden email]]
>>>> Sent: Thursday, August 18, 2005 7:38 PM
>>>> To: [hidden email]
>>>> Subject: [sqlite] How do I attach a database from C++?
>>>>
>>>> I'm having difficulty attaching a database from C++.
>>>>
>>>> Within my code, I'm using an sqlite3_prepare call:
>>>>
>>>>          prepareResult = pSqlBundle->sqlite3_prepare (db_, "ATTACH
>>>> DATABASE 'window_5.sdb' AS W5;", -1, &attachSqlStmt,  
>>>> &tailOfSqlStmt);
>>>>
>>>> but it returns an error (i.e., prepareResult comes back as
>>>> SQLITE_ERROR).
>>>>
>>>> Just to make sure that there were no problems with the databases or
>>>> my syntax, I tried the attach command (i.e., ATTACH DATABASE
>>>> 'window_5.sdb' AS W5;) from the command line, and everything worked
>>>> fine.  I tried using the full path name for the database-filename,
>>>> but that didn't work either.
>>>>
>>>> I'm sure it's something simple, but what I'm I doing wrong?
>>>>
>>>> Thanks,
>>>> Greg
>>>>
>>>>
>>>>
>>>
>>>
>>>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: How do I attach a database from C++?

Greg Stark-4
In reply to this post by Puneet Kishor

On Aug 19, 2005, at 9:37 AM, Puneet Kishor wrote:

> Greg Stark wrote:
>
>> Tom,
>> I appreciate you're help but I'm pretty sure that the semicolon  
>> has  to be there (well. at least it's required in all the other  
>> statements  I've written to date -- this one statement is part of  
>> a much large  program that's working fine other than for this one  
>> ATTACH).
>> My guess is that SQLite3 doesn't know where to find my database,  
>> but  I'm not sure how to tell it where to look.
>>
>
> well, have you tried giving it the full path name to the database?
>

You may have a good point.  I've been entering the full path the same  
way as I would in unix ('/Users/bsllc/Development/databases/
window_5.sdb'), but is this proper syntax for a path within SQLite3?

-Greg


>
>
>> -Greg
>> On Aug 19, 2005, at 6:07 AM, Thomas Briggs wrote:
>>
>>>
>>>    I think that the semi-colon at the end of the statement is what's
>>> causing your problem.  The command shell requires the semi-colon  
>>> to  mark
>>> the end of a statement; in code, your statement ends at the end  
>>> of the
>>> string.
>>>
>>>    -Tom
>>>
>>>
>>>
>>>> -----Original Message-----
>>>> From: Greg Stark [mailto:[hidden email]]
>>>> Sent: Thursday, August 18, 2005 7:38 PM
>>>> To: [hidden email]
>>>> Subject: [sqlite] How do I attach a database from C++?
>>>>
>>>> I'm having difficulty attaching a database from C++.
>>>>
>>>> Within my code, I'm using an sqlite3_prepare call:
>>>>
>>>>          prepareResult = pSqlBundle->sqlite3_prepare (db_, "ATTACH
>>>> DATABASE 'window_5.sdb' AS W5;", -1, &attachSqlStmt,  
>>>> &tailOfSqlStmt);
>>>>
>>>> but it returns an error (i.e., prepareResult comes back as
>>>> SQLITE_ERROR).
>>>>
>>>> Just to make sure that there were no problems with the databases or
>>>> my syntax, I tried the attach command (i.e., ATTACH DATABASE
>>>> 'window_5.sdb' AS W5;) from the command line, and everything worked
>>>> fine.  I tried using the full path name for the database-filename,
>>>> but that didn't work either.
>>>>
>>>> I'm sure it's something simple, but what I'm I doing wrong?
>>>>
>>>> Thanks,
>>>> Greg
>>>>
>>>>
>>>>
>>>
>>>
>>>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: How do I attach a database from C++?

Puneet Kishor
Greg Stark wrote:

>
> On Aug 19, 2005, at 9:37 AM, Puneet Kishor wrote:
>
>> Greg Stark wrote:
>>
>>> Tom,
>>> I appreciate you're help but I'm pretty sure that the semicolon  has  
>>> to be there (well. at least it's required in all the other  
>>> statements  I've written to date -- this one statement is part of  a
>>> much large  program that's working fine other than for this one  
>>> ATTACH).
>>> My guess is that SQLite3 doesn't know where to find my database,  
>>> but  I'm not sure how to tell it where to look.
>>>
>>
>> well, have you tried giving it the full path name to the database?
>>
>
> You may have a good point.  I've been entering the full path the same  
> way as I would in unix ('/Users/bsllc/Development/databases/
> window_5.sdb'), but is this proper syntax for a path within SQLite3?
>


yeah, that is fine if you are on a Unix box. Change it to the Windows
path if you are on a Windows box (C:\\foo\\bar\\window_5.mdb).

 >('/Users/bsllc/Development/databases/ window_5.sdb')

But you have a space above... (at least that is what seems to me in my
email.


>
>
>>
>>
>>> -Greg
>>> On Aug 19, 2005, at 6:07 AM, Thomas Briggs wrote:
>>>
>>>>
>>>>    I think that the semi-colon at the end of the statement is what's
>>>> causing your problem.  The command shell requires the semi-colon  
>>>> to  mark
>>>> the end of a statement; in code, your statement ends at the end  of the
>>>> string.
>>>>
>>>>    -Tom
>>>>
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: Greg Stark [mailto:[hidden email]]
>>>>> Sent: Thursday, August 18, 2005 7:38 PM
>>>>> To: [hidden email]
>>>>> Subject: [sqlite] How do I attach a database from C++?
>>>>>
>>>>> I'm having difficulty attaching a database from C++.
>>>>>
>>>>> Within my code, I'm using an sqlite3_prepare call:
>>>>>
>>>>>          prepareResult = pSqlBundle->sqlite3_prepare (db_, "ATTACH
>>>>> DATABASE 'window_5.sdb' AS W5;", -1, &attachSqlStmt,  &tailOfSqlStmt);
>>>>>
>>>>> but it returns an error (i.e., prepareResult comes back as
>>>>> SQLITE_ERROR).
>>>>>
>>>>> Just to make sure that there were no problems with the databases or
>>>>> my syntax, I tried the attach command (i.e., ATTACH DATABASE
>>>>> 'window_5.sdb' AS W5;) from the command line, and everything worked
>>>>> fine.  I tried using the full path name for the database-filename,
>>>>> but that didn't work either.
>>>>>
>>>>> I'm sure it's something simple, but what I'm I doing wrong?
>>>>>
>>>>> Thanks,
>>>>> Greg
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: How do I attach a database from C++? -- RESOLVED

Greg Stark-4
The problem was that I'd started a transaction prior to attaching the  
second database.  Apparently that's not legal in SQLite3.

On a related issue, does anyone know if nested transactions are  
planned for SQLite?

Thanks again to all those who tried to help!

-Greg

On Aug 19, 2005, at 10:08 AM, Puneet Kishor wrote:

> Greg Stark wrote:
>
>> On Aug 19, 2005, at 9:37 AM, Puneet Kishor wrote:
>>
>>> Greg Stark wrote:
>>>
>>>
>>>> Tom,
>>>> I appreciate you're help but I'm pretty sure that the semicolon  
>>>> has  to be there (well. at least it's required in all the other  
>>>> statements  I've written to date -- this one statement is part  
>>>> of  a much large  program that's working fine other than for  
>>>> this one  ATTACH).
>>>> My guess is that SQLite3 doesn't know where to find my  
>>>> database,  but  I'm not sure how to tell it where to look.
>>>>
>>>>
>>>
>>> well, have you tried giving it the full path name to the database?
>>>
>>>
>> You may have a good point.  I've been entering the full path the  
>> same  way as I would in unix ('/Users/bsllc/Development/databases/  
>> window_5.sdb'), but is this proper syntax for a path within SQLite3?
>>
>
>
> yeah, that is fine if you are on a Unix box. Change it to the  
> Windows path if you are on a Windows box (C:\\foo\\bar\\window_5.mdb).
>
> >('/Users/bsllc/Development/databases/ window_5.sdb')
>
> But you have a space above... (at least that is what seems to me in  
> my email.
>
>
>
>>>
>>>
>>>
>>>> -Greg
>>>> On Aug 19, 2005, at 6:07 AM, Thomas Briggs wrote:
>>>>
>>>>
>>>>>
>>>>>    I think that the semi-colon at the end of the statement is  
>>>>> what's
>>>>> causing your problem.  The command shell requires the semi-
>>>>> colon  to  mark
>>>>> the end of a statement; in code, your statement ends at the  
>>>>> end  of the
>>>>> string.
>>>>>
>>>>>    -Tom
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: Greg Stark [mailto:[hidden email]]
>>>>>> Sent: Thursday, August 18, 2005 7:38 PM
>>>>>> To: [hidden email]
>>>>>> Subject: [sqlite] How do I attach a database from C++?
>>>>>>
>>>>>> I'm having difficulty attaching a database from C++.
>>>>>>
>>>>>> Within my code, I'm using an sqlite3_prepare call:
>>>>>>
>>>>>>          prepareResult = pSqlBundle->sqlite3_prepare (db_,  
>>>>>> "ATTACH
>>>>>> DATABASE 'window_5.sdb' AS W5;", -1, &attachSqlStmt,  
>>>>>> &tailOfSqlStmt);
>>>>>>
>>>>>> but it returns an error (i.e., prepareResult comes back as
>>>>>> SQLITE_ERROR).
>>>>>>
>>>>>> Just to make sure that there were no problems with the  
>>>>>> databases or
>>>>>> my syntax, I tried the attach command (i.e., ATTACH DATABASE
>>>>>> 'window_5.sdb' AS W5;) from the command line, and everything  
>>>>>> worked
>>>>>> fine.  I tried using the full path name for the database-
>>>>>> filename,
>>>>>> but that didn't work either.
>>>>>>
>>>>>> I'm sure it's something simple, but what I'm I doing wrong?
>>>>>>
>>>>>> Thanks,
>>>>>> Greg
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>>>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: How do I attach a database from C++? -- RESOLVED

Kervin L. Pierre
Greg Stark wrote:
> On a related issue, does anyone know if nested transactions are  planned
> for SQLite?
>

We most probably won't be seeing nested
transactions in the near future.  The
issue has come up a few times before :)

It seems to be a common practise to wrap
Sqlite with a wrapper library before
using.  If this is something you did,
you can just count the transaction
levels yourself.  That's what I've done.

The catch with doing simple transaction
counting is that a rollback rolls back
your topmost transaction.  But according
to SQL Server documentation, that's how
MS does it too ( I don't know how Oracle
does it ).

Regards,
Kervin