SQLITE_OPEN_EXCLUSIVE

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

SQLITE_OPEN_EXCLUSIVE

Felipe Gasper
Hi all,

        Does the SQLITE_OPEN_EXCLUSIVE flag exist as analogous to O_EXCL in C
open()? i.e., is this how I can say, “open a database, but only if it’s
a new database”?

        Thank you!

-Felipe Gasper
Houston, TX
_______________________________________________
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: SQLITE_OPEN_EXCLUSIVE

Simon Davies
On 15 March 2015 at 06:06, Felipe Gasper <[hidden email]> wrote:
> Hi all,
>
>         Does the SQLITE_OPEN_EXCLUSIVE flag exist as analogous to O_EXCL in
> C open()? i.e., is this how I can say, “open a database, but only if it’s a
> new database”?

https://www.sqlite.org/capi3ref.html#sqlite3vfsxopen

>         Thank you!
>
> -Felipe Gasper
> Houston, TX

Regards,
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: SQLITE_OPEN_EXCLUSIVE

Simon Slavin-3
In reply to this post by Felipe Gasper

On 15 Mar 2015, at 6:06am, Felipe Gasper <[hidden email]> wrote:

> is this how I can say, “open a database, but only if it’s a new database”?

There is no mode in SQLite which does that.  You can tell it to do the opposite (only open an existing file, return an error if no file exists) but not the way you asked about.

You will have to use file operations to find out whether the file already exists.

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: SQLITE_OPEN_EXCLUSIVE

Felipe Gasper
That approach isn't race-safe, though.

Why does SQLite not allow open via O_EXCL?

-FG

Sent from my android device.

-----Original Message-----
From: Simon Slavin <[hidden email]>
To: General Discussion of SQLite Database <[hidden email]>
Sent: Sun, 15 Mar 2015 7:44 AM
Subject: Re: [sqlite] SQLITE_OPEN_EXCLUSIVE


On 15 Mar 2015, at 6:06am, Felipe Gasper <[hidden email]> wrote:

> is this how I can say, “open a database, but only if it’s a new database”?

There is no mode in SQLite which does that.  You can tell it to do the opposite (only open an existing file, return an error if no file exists) but not the way you asked about.

You will have to use file operations to find out whether the file already exists.

Simon.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
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: SQLITE_OPEN_EXCLUSIVE

Felipe Gasper
In reply to this post by Simon Davies
This seems to support the idea that O_EXCL is SQLITE_OPEN_EXCLUSIVE..?

Sent from my android device.

-----Original Message-----
From: Simon Davies <[hidden email]>
To: General Discussion of SQLite Database <[hidden email]>
Sent: Sun, 15 Mar 2015 4:16 AM
Subject: Re: [sqlite] SQLITE_OPEN_EXCLUSIVE

On 15 March 2015 at 06:06, Felipe Gasper <[hidden email]> wrote:
> Hi all,
>
>         Does the SQLITE_OPEN_EXCLUSIVE flag exist as analogous to O_EXCL in
> C open()? i.e., is this how I can say, “open a database, but only if it’s a
> new database”?

https://www.sqlite.org/capi3ref.html#sqlite3vfsxopen

>         Thank you!
>
> -Felipe Gasper
> Houston, TX

Regards,
Simon
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
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: SQLITE_OPEN_EXCLUSIVE

Simon Davies
On 15 March 2015 at 12:54, Felipe Gasper <[hidden email]> wrote:
> This seems to support the idea that O_EXCL is SQLITE_OPEN_EXCLUSIVE..?

"The SQLITE_OPEN_EXCLUSIVE flag is always used in conjunction with the
SQLITE_OPEN_CREATE flag, which are both directly analogous to the
O_EXCL and O_CREAT flags of the POSIX open() API. The
SQLITE_OPEN_EXCLUSIVE flag, when paired with the SQLITE_OPEN_CREATE,
is used to indicate that file should always be created, and that it is
an error if it already exists. It is not used to indicate the file
should be opened for exclusive access."

I think that is pretty explicit.

Regards,
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: SQLITE_OPEN_EXCLUSIVE

Felipe Gasper
"Violent agreement". :-)

Sent from my android device.

-----Original Message-----
From: Simon Davies <[hidden email]>
To: General Discussion of SQLite Database <[hidden email]>
Sent: Sun, 15 Mar 2015 9:08 AM
Subject: Re: [sqlite] SQLITE_OPEN_EXCLUSIVE

On 15 March 2015 at 12:54, Felipe Gasper <[hidden email]> wrote:
> This seems to support the idea that O_EXCL is SQLITE_OPEN_EXCLUSIVE..?

"The SQLITE_OPEN_EXCLUSIVE flag is always used in conjunction with the
SQLITE_OPEN_CREATE flag, which are both directly analogous to the
O_EXCL and O_CREAT flags of the POSIX open() API. The
SQLITE_OPEN_EXCLUSIVE flag, when paired with the SQLITE_OPEN_CREATE,
is used to indicate that file should always be created, and that it is
an error if it already exists. It is not used to indicate the file
should be opened for exclusive access."

I think that is pretty explicit.

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