4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
11 *************************************************************************
12 ** This file contains code to implement various aspects of UPSERT
13 ** processing and handling of the Upsert object.
15 #include "sqliteInt.h"
17 #ifndef SQLITE_OMIT_UPSERT
19 ** Free a list of Upsert objects
21 void sqlite3UpsertDelete(sqlite3
*db
, Upsert
*p
){
23 Upsert
*pNext
= p
->pUpsertNext
;
24 sqlite3ExprListDelete(db
, p
->pUpsertTarget
);
25 sqlite3ExprListDelete(db
, p
->pUpsertSet
);
26 sqlite3ExprDelete(db
, p
->pUpsertWhere
);
33 ** Duplicate an Upsert object.
35 Upsert
*sqlite3UpsertDup(sqlite3
*db
, Upsert
*p
){
37 return sqlite3UpsertNew(db
,
38 sqlite3UpsertDup(db
, p
->pUpsertNext
),
39 sqlite3ExprListDup(db
, p
->pUpsertTarget
, 0),
40 sqlite3ExprListDup(db
, p
->pUpsertSet
, 0),
41 sqlite3ExprDup(db
, p
->pUpsertWhere
, 0)
46 ** Create a new Upsert object.
48 Upsert
*sqlite3UpsertNew(
49 sqlite3
*db
, /* Determines which memory allocator to use */
50 Upsert
*pPrior
, /* Append this upsert to the end of the new one */
51 ExprList
*pTarget
, /* Target argument to ON CONFLICT, or NULL */
52 ExprList
*pSet
, /* UPDATE columns, or NULL for a DO NOTHING */
53 Expr
*pWhere
/* WHERE clause for the ON CONFLICT UPDATE */
56 pNew
= sqlite3DbMallocRaw(db
, sizeof(Upsert
));
58 sqlite3UpsertDelete(db
, pPrior
);
59 sqlite3ExprListDelete(db
, pTarget
);
60 sqlite3ExprListDelete(db
, pSet
);
61 sqlite3ExprDelete(db
, pWhere
);
64 pNew
->pUpsertTarget
= pTarget
;
65 pNew
->pUpsertSet
= pSet
;
66 pNew
->pUpsertNext
= pPrior
;
67 pNew
->pUpsertWhere
= pWhere
;
72 #endif /* SQLITE_OMIT_UPSERT */