@@ -8,7 +8,7 @@ script "SQLiteLib"
88--
99-- ©2019 revIgniter.com
1010--
11- -- Version 1.0.2
11+ -- Version 1.1.0
1212--
1313-- License: Apache 2.0
1414--
@@ -1706,22 +1706,22 @@ end rigDbFieldData
17061706--| FUNCTION rigDbInsertString
17071707--|
17081708--| Author: rabit
1709- --| Version: 1.1
1710- --| Created: 01 -10-09
1711- --| Last Mod: 14-10-09
1709+ --| Version: 1.2
1710+ --| Created: 2009 -10-01
1711+ --| Last Mod: 2019-08-08
17121712--| Requires: _rigEscapeIdentifiers(), rigDbEscape(), _rigProtectIdentifiers(), _rigInsert()
17131713--|
17141714--| Summary: Generate an insert string.
17151715--|
1716- --| Format: rigDbInsertString(param1, param2)
1716+ --| Format: rigDbInsertString(param1, param2[, param3] )
17171717--|
17181718--| Parameters: string <pTable> the table upon which the query will be performed,
1719- --| array <pData> an associative array data of key/values
1719+ --| array <pData> an associative array data of key/values, bool <pReplace> (optional)
17201720--|
17211721--| Return: string
17221722----------------------------------------------------------------------*/
17231723
1724- function rigDbInsertString pTable pData
1724+ function rigDbInsertString pTable pData pReplace
17251725 local tCounter , tVal , tFields , tValues , tTable
17261726
17271727 put 0 into tCounter
@@ -1735,7 +1735,7 @@ function rigDbInsertString pTable pData
17351735
17361736 put _rigProtectIdentifiers(pTable , TRUE , NULL , FALSE ) into tTable
17371737
1738- return _rigInsert(tTable , tFields , tValues )
1738+ return _rigInsert(tTable , tFields , tValues , pReplace )
17391739end rigDbInsertString
17401740
17411741
@@ -2840,25 +2840,30 @@ end _rigFromTables
28402840--| FUNCTION _rigInsert
28412841--|
28422842--| Author: rabit
2843- --| Version: 1.0
2844- --| Created: 11 -04-14
2845- --| Last Mod: --
2843+ --| Version: 1.1
2844+ --| Created: 2014 -04-11
2845+ --| Last Mod: 2019-08-08
28462846--| Requires: --
28472847--|
28482848--| Summary: Generates a platform-specific insert string from the supplied data.
28492849--|
2850- --| Format: _rigInsert(param1, param2, param3)
2850+ --| Format: _rigInsert(param1, param2, param3[, param4] )
28512851--|
2852- --| Parameters: string <pTable> the table name, array <pKeys> the insert keys, array <pValues> the insert values
2852+ --| Parameters: string <pTable> the table name, array <pKeys> the insert keys,
2853+ --| array <pValues> the insert values, bool <pReplace> (optional)
28532854--|
28542855--| Return: string
28552856----------------------------------------------------------------------*/
28562857
2857- private function _rigInsert pTable pKeys pValues
2858+ private function _rigInsert pTable pKeys pValues pReplace
28582859 combine pKeys using comma
28592860 combine pValues using comma
28602861
2861- return "INSERT INTO " & pTable & " (" & pKeys & ") VALUES (" & pValues & ")"
2862+ if pReplace <> TRUE then
2863+ return "INSERT INTO " & pTable & " (" & pKeys & ") VALUES (" & pValues & ")"
2864+ else
2865+ return "INSERT OR REPLACE INTO " & pTable & " (" & pKeys & ") VALUES (" & pValues & ")"
2866+ end if
28622867end _rigInsert
28632868
28642869
@@ -6372,24 +6377,25 @@ end rigDbGetWhere
63726377--| FUNCTION rigDbInsert
63736378--|
63746379--| Author: rabit
6375- --| Version: 1.0
6376- --| Created: 22 -04-14
6377- --| Last Mod: --
6380+ --| Version: 1.1
6381+ --| Created: 2014 -04-22
6382+ --| Last Mod: 2019-08-08
63786383--| Requires: rigDbValuesSet(), dbErrorHandling, _rigProtectIdentifiers(), rigArrayKeys()
63796384--| rigArrayValues(), _rigInsert(), _rigResetWrite, rigDbQuery(), _rigDbLastInsertID()
63806385--|
63816386--| Summary: Compiles an insert string and runs the query.
63826387--|
6383- --| Format: rigDbInsert(param1, param2, param3)
6388+ --| Format: rigDbInsert(param1, param2[ , param3][, param4] )
63846389--|
63856390--| Parameters: string <pTable> the table to retrieve the results from, array <pInsertVals>
63866391--| an associative array of insert values, bool <pLastInsertID> flag which determines
6387- --| if the last automatically generated ID value of an AUTO_INCREMENT column should be returned
6392+ --| if the last automatically generated ID value of an AUTO_INCREMENT column should be returned (optional),
6393+ --| bool <pReplace> (optional)
63886394--|
63896395--| Return: mixed
63906396----------------------------------------------------------------------*/
63916397
6392- function rigDbInsert pTable pInsertVals pLastInsertID
6398+ function rigDbInsert pTable pInsertVals pLastInsertID pReplace
63936399 local tInsertVals , tLastInsertID , tTable , tArrayKeys , tArrayValues , tSQL , tResultVal
63946400
63956401 if pInsertVals is an array then
@@ -6431,7 +6437,7 @@ function rigDbInsert pTable pInsertVals pLastInsertID
64316437 put rigArrayKeys(sActiveRecord ["set" ]) into tArrayKeys
64326438 put rigArrayValues(sActiveRecord ["set" ], FALSE ) into tArrayValues -- use apostrophes (false) is already done by rigDbValuesSet(pInsertVals)
64336439
6434- put _rigInsert(tTable , tArrayKeys , tArrayValues ) into tSQL
6440+ put _rigInsert(tTable , tArrayKeys , tArrayValues , pReplace ) into tSQL
64356441
64366442 _rigResetWrite
64376443
@@ -6450,6 +6456,61 @@ end rigDbInsert
64506456
64516457
64526458
6459+ /* ----------------------------------------------------------------------
6460+ --| COMMAND rigDBinsertQueryArray
6461+ --|
6462+ --| Author: rabit
6463+ --| Version: 1.0
6464+ --| Created: 2019-08-08
6465+ --| Last Mod: --
6466+ --| Requires: rigDbInsert(), dbErrorHandling
6467+ --|
6468+ --| Summary: Insert data returned by a database query.
6469+ --|
6470+ --| Format: rigDBinsertQueryArray param1, param2[, param3]
6471+ --|
6472+ --| Parameters: string <pTableName>, array <pTableA> the array returned by a query, bool <pReplace> (optional)
6473+ --|
6474+ --| Return: empty
6475+ ----------------------------------------------------------------------*/
6476+
6477+ command rigDBinsertQueryArray pTableName pTableA pReplace
6478+ local tTableKeys , tFieldNamesA , tNumFields
6479+ local tKey , tRowA , tFieldNum , tDataA
6480+
6481+ if pTableA is an array then
6482+
6483+ if pTableA ["numrows" ] > 0 then
6484+ put the keys of pTableA ["resultarray" ] into tTableKeys
6485+ sort lines of tTableKeys ascending numeric
6486+
6487+ put pTableA ["fieldnames" ] into tFieldNamesA
6488+ put the number of lines in the keys of tFieldNamesA into tNumFields
6489+
6490+ -- repeat for each key tKey in pTableA["resultarray"]
6491+ repeat for each line tKey in tTableKeys
6492+
6493+ put pTableA ["resultarray" ][tKey ] into tRowA
6494+
6495+ repeat with tFieldNum = 1 to tNumFields
6496+ put tRowA [tFieldNum ] into tDataA [tFieldNamesA [tFieldNum ]]
6497+ end repeat
6498+
6499+ get rigDbInsert(pTableName , tDataA , , pReplace )
6500+ if it is FALSE then
6501+ dbErrorHandling "Insertion failed!"
6502+ end if
6503+ end repeat
6504+ end if -- if pTableA["numrows"] > 0
6505+ end if -- if pTableA is an array
6506+ end rigDBinsertQueryArray
6507+
6508+
6509+
6510+
6511+
6512+
6513+
64536514/* ----------------------------------------------------------------------
64546515--| FUNCTION rigDbUpdate
64556516--|
0 commit comments