50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
using Microsoft.Data.Sqlite;
|
|
using Project.Model;
|
|
namespace Project.Persistence;
|
|
|
|
public partial class SQLite
|
|
{
|
|
//Method to save a new entry to SAVED_LOGINS
|
|
public static void SaveEntry(string name, string pass, string mailUsername, string url, string? note,
|
|
string ownerUsername)
|
|
{
|
|
using var connection = new SqliteConnection($"Data Source={_dbPath}");
|
|
connection.Open();
|
|
using (var command = connection.CreateCommand())
|
|
{
|
|
command.Parameters.AddWithValue("@name", name);
|
|
command.Parameters.AddWithValue("@pass", pass);
|
|
command.Parameters.AddWithValue("@mail_username", mailUsername);
|
|
command.Parameters.AddWithValue("@url", url);
|
|
command.Parameters.AddWithValue("@note", note ?? "");
|
|
command.Parameters.AddWithValue("@owner", ownerUsername);
|
|
|
|
command.CommandText =
|
|
@"
|
|
INSERT INTO SAVED_LOGINS (name, pass, mail_username, url, note, owner)
|
|
VALUES (@name, @pass, @mail_username,@url, @note, @owner);";
|
|
command.ExecuteNonQuery();
|
|
}
|
|
}
|
|
|
|
//get all the entries from the saved_logins table that are for the current user
|
|
/*
|
|
public static string? GetEntries(string username)
|
|
{
|
|
using var connection = new SqliteConnection($"Data Source={_dbPath}");
|
|
connection.Open();
|
|
|
|
using (var command = connection.CreateCommand())
|
|
{
|
|
command.Parameters.AddWithValue("@currentuser", username);
|
|
command.CommandText =
|
|
@"SELECT name, pass, mail_username,url, note, owner
|
|
FROM SAVED_LOGINS
|
|
WHERE owner = @currentuser
|
|
";
|
|
var result = command.ExecuteScalar();
|
|
return result?.ToString();
|
|
}
|
|
}
|
|
*/
|
|
} |