Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, May 2007
Knowing if sqlite database exists

Pages: Prev | 1 | 2 | Next

Message 1 in thread

Hello all,

I have an application using sqlite, however, in the first run I need
to create the database tables and initialize some other stuff. How can
I check if it is the first run or not, i.e. if I need to call the
function for table creation?

Cheers,

-- 
 [ signature omitted ] 

Message 2 in thread

Hello, Paulo J. Matos
12.05.2007 19:06 you wrote:
> Hello all,
> 
> I have an application using sqlite, however, in the first run I need
> to create the database tables and initialize some other stuff. How can
> I check if it is the first run or not, i.e. if I need to call the
> function for table creation?
> 
> Cheers,
> 

Check if tables already exists with QSqlDatabase::tables, or tables 
structure with QSqlDatabase::record ?

--
 [ signature omitted ] 

Message 3 in thread

On 5/14/07, Nikolay Moskvichev <nikolay.moskvichev@xxxxxxxxx> wrote:
> Hello, Paulo J. Matos
> 12.05.2007 19:06 you wrote:
> > Hello all,
> >
> > I have an application using sqlite, however, in the first run I need
> > to create the database tables and initialize some other stuff. How can
> > I check if it is the first run or not, i.e. if I need to call the
> > function for table creation?
> >
> > Cheers,
> >
>
> Check if tables already exists with QSqlDatabase::tables, or tables
> structure with QSqlDatabase::record ?
>

Ah, that's the cool solution, I think.

Thank you very much! :D

> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>
>


-- 
 [ signature omitted ] 

Message 4 in thread

Hello,

I am using Qt4 and would like to load files that are dropped anywhere
within the main window of my application. I do this by installing an
event filter but I am stuck at the point where I need to extract the
path and name of the file that was dropped. The format of the MIME data
of the drop event is:

application/x-qt-windows-mime;value="Shell IDList Array"

This is a Windows format with an array of PIDLs which is not exactly
what I would like to deal with. Is there any way to obtain the path and
name of the file in a non-platform-specific way? It feels like I am
making an easy thing into something complicated here.

Best Regards,
Daniel Hedberg

--
 [ signature omitted ] 

Message 5 in thread

drag&drop data typically comes in multiple flavors.
you probably want to pick some other mime type...

if (event->mimeData()->hasFormat("text/plain"))
	...
	
Cheers,
Peter

> -----Ursprüngliche Nachricht-----
> Von: Daniel Hedberg [mailto:daniel.hedberg@xxxxxxxxxxxx]
> Gesendet: Montag, 14. Mai 2007 14:10
> An: qt-interest@xxxxxxxxxxxxx
> Betreff: Drag & Drop of files.
> 
> Hello,
> 
> I am using Qt4 and would like to load files that are dropped anywhere
> within the main window of my application. I do this by installing an
> event filter but I am stuck at the point where I need to extract the
> path and name of the file that was dropped. The format of the MIME data
> of the drop event is:
> 
> application/x-qt-windows-mime;value="Shell IDList Array"
> 
> This is a Windows format with an array of PIDLs which is not exactly
> what I would like to deal with. Is there any way to obtain the path and
> name of the file in a non-platform-specific way? It feels like I am
> making an easy thing into something complicated here.
> 
> Best Regards,
> Daniel Hedberg
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 6 in thread

Problem is that the data is generated by MS Windows as I am dragging a file from the MS Windows file explorer and dropping it on my window.

Therefore, event->mimeData()->hasFormat("text/plain") returns false.

I thought maybe Qt had some mechanism for handling this in a platform independent way. This was possible in Qt3 as the MIME data actually was plain text, but in Qt4 it is not.

Best Regards,
Daniel Hedberg

-----Original Message-----
From: Peter Prade [mailto:prade@xxxxxxxxxxx] 
Sent: den 14 maj 2007 17:17
To: qt-interest@xxxxxxxxxxxxx
Subject: AW: Drag & Drop of files.

drag&drop data typically comes in multiple flavors.
you probably want to pick some other mime type...

if (event->mimeData()->hasFormat("text/plain"))
	...
	
Cheers,
Peter

> -----Ursprüngliche Nachricht-----
> Von: Daniel Hedberg [mailto:daniel.hedberg@xxxxxxxxxxxx]
> Gesendet: Montag, 14. Mai 2007 14:10
> An: qt-interest@xxxxxxxxxxxxx
> Betreff: Drag & Drop of files.
> 
> Hello,
> 
> I am using Qt4 and would like to load files that are dropped anywhere
> within the main window of my application. I do this by installing an
> event filter but I am stuck at the point where I need to extract the
> path and name of the file that was dropped. The format of the MIME data
> of the drop event is:
> 
> application/x-qt-windows-mime;value="Shell IDList Array"
> 
> This is a Windows format with an array of PIDLs which is not exactly
> what I would like to deal with. Is there any way to obtain the path and
> name of the file in a non-platform-specific way? It feels like I am
> making an easy thing into something complicated here.
> 
> Best Regards,
> Daniel Hedberg
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 7 in thread

Maybe you could parse the returned value of  QMimeData::formats() to see
if you can work with one of formats (if any other format that window is 
returned of course!)

Daniel Hedberg a écrit :

>Problem is that the data is generated by MS Windows as I am dragging a file from the MS Windows file explorer and dropping it on my window.
>
>Therefore, event->mimeData()->hasFormat("text/plain") returns false.
>
>I thought maybe Qt had some mechanism for handling this in a platform independent way. This was possible in Qt3 as the MIME data actually was plain text, but in Qt4 it is not.
>
>Best Regards,
>Daniel Hedberg
>
>-----Original Message-----
>From: Peter Prade [mailto:prade@xxxxxxxxxxx] 
>Sent: den 14 maj 2007 17:17
>To: qt-interest@xxxxxxxxxxxxx
>Subject: AW: Drag & Drop of files.
>
>drag&drop data typically comes in multiple flavors.
>you probably want to pick some other mime type...
>
>if (event->mimeData()->hasFormat("text/plain"))
>	...
>	
>Cheers,
>Peter
>
>  
>
>>-----Ursprüngliche Nachricht-----
>>Von: Daniel Hedberg [mailto:daniel.hedberg@xxxxxxxxxxxx]
>>Gesendet: Montag, 14. Mai 2007 14:10
>>An: qt-interest@xxxxxxxxxxxxx
>>Betreff: Drag & Drop of files.
>>
>>Hello,
>>
>>I am using Qt4 and would like to load files that are dropped anywhere
>>within the main window of my application. I do this by installing an
>>event filter but I am stuck at the point where I need to extract the
>>path and name of the file that was dropped. The format of the MIME data
>>of the drop event is:
>>
>>application/x-qt-windows-mime;value="Shell IDList Array"
>>
>>This is a Windows format with an array of PIDLs which is not exactly
>>what I would like to deal with. Is there any way to obtain the path and
>>name of the file in a non-platform-specific way? It feels like I am
>>making an easy thing into something complicated here.
>>
>>Best Regards,
>>Daniel Hedberg
>>
>>--
>>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>>"unsubscribe" in the subject or the body.
>>List archive and information: http://lists.trolltech.com/qt-interest/
>>    
>>
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>  
>


Message 8 in thread

Ah, yes... that works! I was so focused on the text/plain" format that I missed the "text/uri-list" format which works perfectly well! Thank you Veronique (and Peter) for pointing me in the right direction!

 

Best Regards,

Daniel Hedberg

 

________________________________

From: veronique.lefrere@xxxxxx [mailto:veronique.lefrere@xxxxxx] 
Sent: den 14 maj 2007 18:29
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Drag & Drop of files.

 

Maybe you could parse the returned value of  QMimeData::formats() to see 
if you can work with one of formats (if any other format that window is returned of course!)

Daniel Hedberg a écrit : 

Problem is that the data is generated by MS Windows as I am dragging a file from the MS Windows file explorer and dropping it on my window.
 
Therefore, event->mimeData()->hasFormat("text/plain") returns false.
 
I thought maybe Qt had some mechanism for handling this in a platform independent way. This was possible in Qt3 as the MIME data actually was plain text, but in Qt4 it is not.
 
Best Regards,
Daniel Hedberg
 
-----Original Message-----
From: Peter Prade [mailto:prade@xxxxxxxxxxx] 
Sent: den 14 maj 2007 17:17
To: qt-interest@xxxxxxxxxxxxx
Subject: AW: Drag & Drop of files.
 
drag&drop data typically comes in multiple flavors.
you probably want to pick some other mime type...
 
if (event->mimeData()->hasFormat("text/plain"))
        ...
        
Cheers,
Peter
 
  

	-----Ursprüngliche Nachricht-----
	Von: Daniel Hedberg [mailto:daniel.hedberg@xxxxxxxxxxxx]
	Gesendet: Montag, 14. Mai 2007 14:10
	An: qt-interest@xxxxxxxxxxxxx
	Betreff: Drag & Drop of files.
	 
	Hello,
	 
	I am using Qt4 and would like to load files that are dropped anywhere
	within the main window of my application. I do this by installing an
	event filter but I am stuck at the point where I need to extract the
	path and name of the file that was dropped. The format of the MIME data
	of the drop event is:
	 
	application/x-qt-windows-mime;value="Shell IDList Array"
	 
	This is a Windows format with an array of PIDLs which is not exactly
	what I would like to deal with. Is there any way to obtain the path and
	name of the file in a non-platform-specific way? It feels like I am
	making an easy thing into something complicated here.
	 
	Best Regards,
	Daniel Hedberg
	 
	--
	To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
	"unsubscribe" in the subject or the body.
	List archive and information: http://lists.trolltech.com/qt-interest/
	    

 
--
 [ signature omitted ] 

Message 9 in thread

Paulo J. Matos schrieb:
> Hello all,
> 
> I have an application using sqlite, however, in the first run I need
> to create the database tables and initialize some other stuff. How can
> I check if it is the first run or not, i.e. if I need to call the
> function for table creation?

How about QFile::exists()? Or a flag in QSettings?

Martin

-- 
 [ signature omitted ] 

Message 10 in thread

On 5/14/07, Martin Gebert <Martin.Gebert@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> Paulo J. Matos schrieb:
> > Hello all,
> >
> > I have an application using sqlite, however, in the first run I need
> > to create the database tables and initialize some other stuff. How can
> > I check if it is the first run or not, i.e. if I need to call the
> > function for table creation?
>
> How about QFile::exists()?

File? But I never create a file in sqlite... It's the first time I'm
using sqlite, am I missing something? Even when using Qt I never
create a file, I have a name for the DB, I create  and manage it.
Nothing else!

> Or a flag in QSettings?

That's a possibility.

Thank you!

>
> Martin
>
> --
> To mail me in private, please remove the -NOSPAM- part from the address
> above.
>
> Ultimate Truths in software development # 5:
> If it ain't broken, don't fix it.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>
>


-- 
 [ signature omitted ] 

Message 11 in thread

Paulo J. Matos schrieb:
>> > I have an application using sqlite, however, in the first run I need
>> > to create the database tables [...]
>>
>> How about QFile::exists()?
> 
> File? But I never create a file in sqlite... It's the first time I'm
> using sqlite, am I missing something? Even when using Qt I never
> create a file, I have a name for the DB, I create  and manage it.
> Nothing else!

Well, then, where does SQLite store your data permanently?
Yes, I think you're missing the particularities SQLite. You may want to read
http://www.sqlite.org/different.html
esp. section "Single Database File", and
http://www.sqlite.org/capi3ref.html#sqlite3_open

Martin

-- 
 [ signature omitted ] 

Message 12 in thread

As an afterthought: Checking for the DB file isn't portable to other 
DBMS, as Nikolays solution is, and using a DBMS independent solution 
would be cleaner, of course. However, it wouldn't hurt to know the 
idiosyncrasies of the DBMS you're writing your software for in the first 
place... ;-)

Martin

-- 
 [ signature omitted ] 

Message 13 in thread

On 5/14/07, Martin Gebert <Martin.Gebert@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> Paulo J. Matos schrieb:
> >> > I have an application using sqlite, however, in the first run I need
> >> > to create the database tables [...]
> >>
> >> How about QFile::exists()?
> >
> > File? But I never create a file in sqlite... It's the first time I'm
> > using sqlite, am I missing something? Even when using Qt I never
> > create a file, I have a name for the DB, I create  and manage it.
> > Nothing else!
>
> Well, then, where does SQLite store your data permanently?
> Yes, I think you're missing the particularities SQLite. You may want to read
> http://www.sqlite.org/different.html
> esp. section "Single Database File", and
> http://www.sqlite.org/capi3ref.html#sqlite3_open
>

But Qt doesn't ask for a path. So does it store the file in any
special default place?

> Martin
>
> --
> To mail me in private, please remove the -NOSPAM- part from the address
> above.
>
> Ultimate Truths in software development # 4:
> DRY
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>
>


-- 
 [ signature omitted ] 

Message 14 in thread

Hi,

> But Qt doesn't ask for a path. So does it store the file in any
> special default place?

I think the documentation isn't very clear:
http://doc.trolltech.com/4.2/qsqldatabase.html#setDatabaseName
There's a paragraph about Microsoft Access:
	For example, Microsoft Access users can use the following
	connection string to open an .mdb file directly, instead
	of having to create a DSN entry in the ODBC manager:
	...
	db = QSqlDatabase::addDatabase("QODBC");
	db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};
		FIL={MS Access};DBQ=myaccessfile.mdb");
	if (db.open()) {
	    // success!
	}
	...
but unfortunately nothing relating to SQLite.

The database name is used to create a file that contains a file the SQLite 
database. If you provide a name such as "foo" without a full path, my guess is 
that the database will be created in a file "foo" in the current directory, 
which isn't a very good idea. I didn't look at the source code of Qt, so this 
is just a guess.

--
 [ signature omitted ] 

Message 15 in thread

> The database name is used to create a file that contains a file the 
> SQLite database. If you provide a name such as "foo" without a full 
> path, my guess is that the database will be created in a file "foo" in 
> the current directory, which isn't a very good idea. I didn't look at 
> the source code of Qt, so this is just a guess.

That's correct, IIRC. Better specify a path to avoid unwanted surprises.
See the docs in 
doc/html/sql-driver.html#qsqlite-for-sqlite-version-3-and-above:

'SQLite operates on a single file, which must be set as the database 
name when opening a connection. If the file does not exist, SQLite will 
try to create it. SQLite also supports in-memory databases, simply pass 
":memory:" as the database name.'

Martin

-- 
 [ signature omitted ] 

Pages: Prev | 1 | 2 | Next