Using a `new GUID()` as a key in Sqlite (C#)

0

working on a small tool, and I want to store information on a per-app basis, so I'm using SQLite.

I have the code implemented in order to get the record in the database, and pull it from the database, etc.

On my insert however, I'm getting an error stating

Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'unrecognized token: "60ca7952"'. at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db) at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior) at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader() at Microsoft.Data.Sqlite.SqliteCommand.ExecuteNonQuery()

for an insert that looks like this:

cmd.CommandText = $"INSERT INTO FILES(Id, Path, DeleteOnExpiry, ExpirationDate, CreationTime) values({(string) f.Id}, {f.Path}, {f.DeleteOnExpiry}, {f.ExpirationDate}, {f.CreationTime})";

The ID field is a GUID, as I wanted a long, always unique key.

How can I "fix" the GUID to insert safely into the SQLite db file?

c#
.net
sqlite

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0