personio/functions/sqlite.ps1
2024-07-26 19:37:06 +02:00

62 lines
2.7 KiB
PowerShell

Function CREATE-SQLITE($USERID = "") {
$db = "$($ScriptDir)\sqlite\$($USERID).db"
$query = "CREATE TABLE vacation (
Id INTEGER PRIMARY KEY NOT NULL,
Mail NVARCHAR(250) NOT NULL,
Userid NVARCHAR(250) NOT NULL,
Firstname NVARCHAR(250) NOT NULL,
Lastname NVARCHAR(250) NOT NULL,
Vacexchangeid NVARCHAR(250),
Vactype NVARCHAR(250) NOT NULL,
Vacstart NVARCHAR(250) NOT NULL,
Vacend NVARCHAR(250) NOT NULL
)"
# SQLite erstellt die Datei automatisch
Invoke-SqliteQuery -Query $query -DataSource $db
}
Function INSERT-SQLITE($USERID = "", $MAIL = "", $FIRSTNAME = "", $LASTNAME = "", $VACPERSONIOID = "", $VAEXCHANGEID = 0, $VACTYPE = "", $VACSTART = "", $VACEND = "") {
$db = "$($ScriptDir)\sqlite\$($USERID).db"
$query = "INSERT INTO vacation(id, Mail, Userid, Firstname, Lastname, Vacexchangeid, Vactype, Vacstart, Vacend) VALUES ( '$($VACPERSONIOID)', '$($MAIL)', '$($USERID)', '$($FIRSTNAME)', '$($LASTNAME)', '$($VAEXCHANGEID)', '$($VACTYPE)', '$($VACSTART)', '$($VACEND)' );"
Invoke-SqliteQuery -Query $query -DataSource $db
}
Function DELETE-SQLITE($USERID = "", $VACPERSONIOID = "" ) {
$db = "$($ScriptDir)\sqlite\$($USERID).db"
$query = "DELETE FROM vacation WHERE id LIKE '$($VACPERSONIOID)';"
Invoke-SqliteQuery -Query $query -DataSource $db
}
Function GET-SQLITEByExID($USERID = "", $EXID = "") {
$db = "$($ScriptDir)\sqlite\$($USERID).db"
$query = "SELECT Id FROM ``vacation`` WHERE Vacexchangeid LIKE '%$($EXID)';"
$RESPONSE = Invoke-SqliteQuery -Query $query -DataSource $db
Return $RESPONSE
}
Function DELETE-WRONGSQLITEDATA($USERID = "" ) {
$db = "$($ScriptDir)\sqlite\$($USERID).db"
$query = "DELETE FROM vacation WHERE Vacexchangeid LIKE 'False';"
Invoke-SqliteQuery -Query $query -DataSource $db
}
Function GET-SQLITE($USERID = "", $VACPERSONIOID = "") {
$db = "$($ScriptDir)\sqlite\$($USERID).db"
$query = "SELECT * FROM vacation WHERE id LIKE '$($VACPERSONIOID)';"
$RESPONSE = Invoke-SqliteQuery -Query $query -DataSource $db
Return $RESPONSE
}
Function GET-SQLITEUSERAPPOINTMENTS($USERID = "") {
$STARTDATE="$((Get-Date).AddDays(-28).ToString('yyyy-MM-dd'))"
$db = "$($ScriptDir)\sqlite\$($USERID).db"
# $query = "SELECT id FROM vacation WHERE Userid LIKE '$($USERID)';"
$query = "SELECT Id FROM ``vacation`` WHERE DATE(substr(Vacstart,7,4)||'-'||substr(Vacstart,1,2)||'-'||substr(Vacstart,4,2)) BETWEEN DATE('$($STARTDATE)') AND DATE('2222-12-31') AND Userid LIKE '$($USERID)';"
$RESPONSE = Invoke-SqliteQuery -Query $query -DataSource $db
Return $RESPONSE
}