SQLITE Query Successful command line faile RR

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Kevin
Posts: 74
Joined: Fri Oct 02, 2009 3:47 pm

SQLITE Query Successful command line faile RR

Post by Kevin » Fri Oct 30, 2009 9:09 pm

This query is successful from the command line but fails with revdberr. Any suggestions?

SELECT strftime('%s','now','localtime');

Kevin
Posts: 74
Joined: Fri Oct 02, 2009 3:47 pm

SQLite output.

Post by Kevin » Fri Oct 30, 2009 9:29 pm

SQLite version 3.6.19
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> SELECT datetime('now');
2009-10-30 20:26:17
sqlite> SELECT datetime('now', 'localtime');
2009-10-30 15:26:50
sqlite> SELECT strftime('%s','now','localtime');
1256916457
sqlite>

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Oct 30, 2009 10:38 pm

Dear Kevin,

Please post (the relevant part of) your Revolution script.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Kevin
Posts: 74
Joined: Fri Oct 02, 2009 3:47 pm

Transcript.

Post by Kevin » Fri Oct 30, 2009 11:05 pm

on mouseUp

local _db
local _now

--
--In memory only no database file needed here
--
put revOpenDatabase("sqlite",,,,,,,) into _db
put revDataFromQuery(comma,return,"SELECT datetime('now');") into _now
revCloseDatabase _db

end mouseUp

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Oct 30, 2009 11:09 pm

Kevin,

In

revOpenDatabase("sqlite",,,,,,,)

you have to specify not only the type of database, but also the database name or file path and possibly a user name and password.

Note that the command line version and the Revolution version do not interact in any way. The two have nothing to do with each other, except that both of them were compiled using the same library.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Kevin
Posts: 74
Joined: Fri Oct 02, 2009 3:47 pm

Sorry.

Post by Kevin » Fri Oct 30, 2009 11:12 pm

The SQLite creates a in memory only database when no file is specified. This is common with using the library.

Kevin
Posts: 74
Joined: Fri Oct 02, 2009 3:47 pm

SQLite

Post by Kevin » Fri Oct 30, 2009 11:13 pm

I have used this exact same behavior in C++, C, REALBasic and several other languages!

Kevin
Posts: 74
Joined: Fri Oct 02, 2009 3:47 pm

Example command line

Post by Kevin » Fri Oct 30, 2009 11:23 pm

C:\SQLite\sqlite-3_6_19>sqlite3.exe
SQLite version 3.6.19
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> SELECT datetime('now' 'utc');
SQL error: near "'utc'": syntax error
sqlite> SELECT datetime('now','utc');
2009-10-31 03:22:24
sqlite>

Kevin
Posts: 74
Joined: Fri Oct 02, 2009 3:47 pm

Example RB Linux

Post by Kevin » Fri Oct 30, 2009 11:26 pm

Function LocalToUTC( ByVal As Date ) As Date

Dim oDb As New REALSQLDatabase
Dim iOffset As Integer
Dim oError As New Date

oError.TotalSeconds = 0

If False = oDb.Connect Then

Dim eNoTimeService As New RuntimeException
eNoTimeService.Message = "Missing SQL Time subsystem cannot initialize"

Raise eNoTimeService

End If

Dim sSQL As String

sSQL = "SELECT strftime(""%s&"", 'now', 'localtime') - strftime(""%s"", 'now')"

Dim oRs As Recordset

oRs = oDb.SQLSelect(sSQL)

If Nil <> oRs Then

iOffset = oRs.IdxField(1).IntegerValue

o.TotalSeconds = o.TotalSeconds - iOffset

Return o

End If


Return oError


End Function

Kevin
Posts: 74
Joined: Fri Oct 02, 2009 3:47 pm

Examples

Post by Kevin » Fri Oct 30, 2009 11:28 pm

As shown in the examples there is no file used it is in memory. Therefore no need for userid or password since I only have the handle.

Thanks,
Kevin

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Oct 30, 2009 11:29 pm

Kevin,

I'm sorry that you are unhappy with the solution I give you, but it is either that or nothing.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Kevin
Posts: 74
Joined: Fri Oct 02, 2009 3:47 pm

Odd

Post by Kevin » Sat Oct 31, 2009 2:08 am

Just found it odd. I am not aware of the functionality Runtime Revolution implements or does not. I have used many forums in the past and have have been given misleading advise just wanted to ensure we we speaking of the same thing.

Kevin

Kevin
Posts: 74
Joined: Fri Oct 02, 2009 3:47 pm

Past example using deatetime() query still fails.

Post by Kevin » Sat Oct 31, 2009 3:05 am

This is from the example (SQLite Sampler.rev) only altered the SQL. Can create tables and insert data. Just cannot see to execute any SQLite date time functions.

on mouseUp
local _db
local _now

put revOpenDatabase("sqlite","AppReg3.db",,,,,,) into _db
put revDataFromQuery(comma,return,"SELECT datetime('now','utc');") into _now
revCloseDatabase _db
end mouseUp

Kevin
Posts: 74
Joined: Fri Oct 02, 2009 3:47 pm

Miss the small things

Post by Kevin » Sat Oct 31, 2009 3:20 am

put revDataFromQuery(comma,return,"SELECT datetime('now');") into _now

Forgot the handle to the database.

Kevin
Posts: 74
Joined: Fri Oct 02, 2009 3:47 pm

The answer for those following...

Post by Kevin » Sat Oct 31, 2009 3:31 am

on mouseUp
local _db
local _now

put revOpenDatabase("sqlite",,,,,,,) into _db
put revDataFromQuery(comma,return,_db,"SELECT datetime('now','utc');") into _now
revCloseDatabase _db

end mouseUp

Post Reply