Jump to content

SQLite - ATTACH and SELECT from different db


Iczer
 Share

Recommended Posts

I need to copy difference between 2 db-s into temp memory db make something with it and then copy entries from memory db to one of the two db-s,

but update statement return error in whatever form i try:

$SQLITE_OPEN_URI = 0x40

#include <MsgBoxConstants.au3>
#include <SQLite.au3>

$sPathTo_SourceDB = "E:\Auto-it scripts\testDB_S.sqlite"

$sPathToSDB = StringRegExpReplace($sPathTo_SourceDB, "\\", "/")
$sPathToSDB = StringRegExpReplace($sPathToSDB, "\h", "%20")

$sPathTo_DestinDB = "E:\Auto-it scripts\testDB_D.sqlite"

$sPathToDDB = StringRegExpReplace($sPathTo_DestinDB, "\\", "/")
$sPathToDDB = StringRegExpReplace($sPathToDDB, "\h", "%20")

Local $aResult, $iRows, $iColumns, $iRval

_SQLite_StartupEX2("sqlite3.dll")
$hDb = _SQLite_Open(':memory:',$SQLITE_OPEN_READWRITE + $SQLITE_OPEN_URI)

_SQLite_Exec($hDb,"BEGIN; CREATE TABLE IF NOT EXISTS DeltaDB (HKey TEXT PRIMARY KEY NOT NULL, HVal TEXT COLLATE NOCASE);COMMIT;")
_SQLite_Exec($hDb,"ATTACH DATABASE 'file:///" & $sPathToSDB & "?cache=private&mode=ro' AS SourceDB;")
_SQLite_Exec($hDb,"ATTACH DATABASE 'file:///" & $sPathToDDB & "?cache=private&mode=rw' AS DestinDB;")

_SQLite_Exec($hDb,"UPDATE OR IGNORE DeltaDB SET HKey = SourceDB.CasheDB.HKey, HVal = SourceDB.CasheDB.HVal WHERE NOT EXIST " & _ 
                                                                                                    "(SELECT DestinDB.CasheDB.HKey FROM DestinDB.CasheDB WHERE DestinDB.CasheDB.HKey = SourceDB.CasheDB.HKey)")

$iRval = _SQLite_GetTable2d($hDb, "SELECT * FROM DeltaDB;", $aResult, $iRows, $iColumns)

If $iRval = $SQLITE_OK Then
    _SQLite_Display2DResult($aResult)
Else
    MsgBox($MB_SYSTEMMODAL, "SQLite Error: " & $iRval, _SQLite_ErrMsg())
EndIf

_SQLite_Close($hDb)
_SQLite_Shutdown()

 

!   SQLite.au3 Error
--> Function: _SQLite_Exec
--> Query:    UPDATE OR IGNORE ImgDelta SET LinkHash = SourceDB.CasheDB.LinkHash, LocalPath = SourceDB.CasheDB.LocalPath WHERE NOT EXIST (SELECT DestinDB.CasheDB.LinkHash FROM DestinDB.CasheDB WHERE DestinDB.CasheDB.LinkHash = SourceDB.CasheDB.LinkHash)
--> Error:    near "SELECT": syntax error

how i can correct this query?

 

 

Link to comment
Share on other sites

33 minutes ago, Iczer said:

WHERE NOT EXIST (SELECT

WHERE NOT EXISTS (SELECT

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Thanks! I didn't see it...
 but now error changed to:

!   SQLite.au3 Error
--> Function: _SQLite_Exec
--> Query:    UPDATE OR IGNORE ImgDelta SET LinkHash = SourceDB.CasheDB.LinkHash, LocalPath = SourceDB.CasheDB.LocalPath WHERE NOT EXISTS (SELECT DestinDB.CasheDB.LinkHash FROM DestinDB.CasheDB WHERE DestinDB.CasheDB.LinkHash = SourceDB.CasheDB.LinkHash)
--> Error:    no such column: SourceDB.CasheDB.LinkHash

which is wrong - those columns identical to all tables...

Link to comment
Share on other sites

49 minutes ago, Iczer said:

UPDATE OR IGNORE ImgDelta SET

Shouldn't that be:

UPDATE OR IGNORE DeltaDB SET ...

because:

51 minutes ago, Iczer said:

CREATE TABLE IF NOT EXISTS DeltaDB

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

@Iczer, aren't you reinventing sqldiff.exe ?

Also why did you use CachedDB and not implicit main?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...