@@ -92,6 +92,7 @@ class CreateTableWalker
92
92
93
93
private:
94
94
void parsecolumn (Table* table, antlr::RefAST c);
95
+ QString parseConflictClause (antlr::RefAST c);
95
96
96
97
private:
97
98
antlr::RefAST m_root;
@@ -219,6 +220,9 @@ QString PrimaryKeyConstraint::toSql(const FieldVector& applyOn) const
219
220
result += QString (" CONSTRAINT %1 " ).arg (escapeIdentifier (m_name));
220
221
result += QString (" PRIMARY KEY(%1)" ).arg (fieldVectorToFieldNames (applyOn).join (" ," ));
221
222
223
+ if (!m_conflictAction.isEmpty ())
224
+ result += " ON CONFLICT " + m_conflictAction;
225
+
222
226
return result;
223
227
}
224
228
@@ -794,6 +798,10 @@ TablePtr CreateTableWalker::table()
794
798
}
795
799
} while (tc != antlr::nullAST && tc->getType () != sqlite3TokenTypes::RPAREN);
796
800
801
+ // We're either done now or there is a conflict clause
802
+ tc = tc->getNextSibling (); // skip RPAREN
803
+ pk->setConflictAction (parseConflictClause (tc));
804
+
797
805
tab->addConstraint (fields, ConstraintPtr (pk));
798
806
}
799
807
break ;
@@ -1026,6 +1034,9 @@ void CreateTableWalker::parsecolumn(Table* table, antlr::RefAST c)
1026
1034
table->setFullyParsed (false );
1027
1035
con = con->getNextSibling (); // skip
1028
1036
}
1037
+
1038
+ primaryKey->setConflictAction (parseConflictClause (con));
1039
+
1029
1040
if (con != antlr::nullAST && con->getType () == sqlite3TokenTypes::AUTOINCREMENT)
1030
1041
autoincrement = true ;
1031
1042
}
@@ -1145,6 +1156,21 @@ void CreateTableWalker::parsecolumn(Table* table, antlr::RefAST c)
1145
1156
}
1146
1157
}
1147
1158
1159
+ QString CreateTableWalker::parseConflictClause (antlr::RefAST c)
1160
+ {
1161
+ QString conflictAction;
1162
+
1163
+ if (c != antlr::nullAST && c->getType () == sqlite3TokenTypes::ON && c->getNextSibling ()->getType () == sqlite3TokenTypes::CONFLICT)
1164
+ {
1165
+ c = c->getNextSibling (); // skip ON
1166
+ c = c->getNextSibling (); // skip CONFLICT
1167
+ conflictAction = identifier (c);
1168
+ c = c->getNextSibling (); // skip action
1169
+ }
1170
+
1171
+ return conflictAction;
1172
+ }
1173
+
1148
1174
1149
1175
1150
1176
QString IndexedColumn::toString (const QString& indent, const QString& sep) const
0 commit comments