Add some code to export old logs to file
This commit is contained in:
parent
78c31ad6c5
commit
05a58ee907
@ -10,7 +10,7 @@ public class HobbyMain
|
||||
Console.WriteLine("Hello World!");
|
||||
|
||||
// Testing Compressing a file
|
||||
string fileName = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\TeamHobby.Main\archiving2.txt";
|
||||
string fileName = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\TeamHobby.Main\rando";
|
||||
//string fileName = @"arhiving2.txt";
|
||||
FileInfo fileInfo = new FileInfo(fileName);
|
||||
|
||||
|
||||
46
Source Code/TeamHobby.Main/rando
Normal file
46
Source Code/TeamHobby.Main/rando
Normal file
@ -0,0 +1,46 @@
|
||||
title Use Case: Archiving
|
||||
|
||||
participant ArchiveController.cs
|
||||
participant DataConnection
|
||||
participant DataSourceFactory
|
||||
participant SQLSource
|
||||
participant MariaDB
|
||||
|
||||
activate ArchiveController.cs
|
||||
activate DataConnection
|
||||
ArchiveController.cs ->DataConnection:static DataConnection getDataConnection()
|
||||
DataConnection -->ArchiveController.cs:return DataConnection
|
||||
deactivate DataConnection
|
||||
|
||||
activate DataSourceFactory
|
||||
ArchiveController.cs ->DataSourceFactory: new DataSourceFactory()
|
||||
DataSourceFactory ->DataSourceFactory:DataSourceFactory()\nconstructor
|
||||
ArchiveController.cs <-- DataSourceFactory:return DataSourceFactory
|
||||
deactivate DataSourceFactory
|
||||
|
||||
activate SQLSource
|
||||
ArchiveController.cs->SQLSource: IDataSource DataSourceFact.GetDataSource(String sourceName, string info)
|
||||
SQLSource->SQLSource: SQLSource(string info)\nconstructor
|
||||
SQLSource --> ArchiveController.cs :return SQLSource
|
||||
|
||||
loop #lightblue while true
|
||||
alt #lightgreen date == 1
|
||||
ArchiveController.cs ->ArchiveController.cs: string fileName = string CreateFileName( )
|
||||
ArchiveController.cs -> SQLSource: int Compress(string fileName)
|
||||
activate MariaDB
|
||||
|
||||
SQLSource -> MariaDB: int createArchive(string fileLocation)
|
||||
MariaDB -->SQLSource:return 0
|
||||
|
||||
SQLSource ->MariaDB: int RemoveEntries()
|
||||
MariaDB-->SQLSource:return 0
|
||||
end
|
||||
|
||||
|
||||
deactivate MariaDB
|
||||
|
||||
SQLSource-->ArchiveController.cs:return 0
|
||||
end
|
||||
|
||||
deactivate ArchiveController.cs
|
||||
deactivate SQLSource
|
||||
62
src/dbCode/ExportingRows.txt
Normal file
62
src/dbCode/ExportingRows.txt
Normal file
@ -0,0 +1,62 @@
|
||||
|
||||
select * from log;
|
||||
|
||||
-- Find logs that are older than 30 days of current time.
|
||||
SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;
|
||||
|
||||
-- Output logs to a file
|
||||
SELECT * FROM log
|
||||
WHERE
|
||||
DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30
|
||||
INTO OUTFILE 'C:/Temp/oldlogs.csv'
|
||||
FIELDS ENCLOSED BY '"'
|
||||
TERMINATED BY ';'
|
||||
ESCAPED BY '"'
|
||||
LINES TERMINATED BY '\r\n';
|
||||
|
||||
-- Output into comma separated file
|
||||
SELECT * INTO OUTFILE 'C:/Temp/oldlogs2.csv'
|
||||
FIELDS ENCLOSED BY '"'
|
||||
TERMINATED BY ','
|
||||
ESCAPED BY '"'
|
||||
LINES TERMINATED BY '\r\n'
|
||||
FROM log
|
||||
WHERE
|
||||
DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;
|
||||
|
||||
-- Output into comma separated file
|
||||
SELECT *
|
||||
INTO OUTFILE 'C:/Temp/oldlogs4.csv'
|
||||
FIELDS ENCLOSED BY ''
|
||||
TERMINATED BY ','
|
||||
ESCAPED BY '"'
|
||||
LINES TERMINATED BY '\r\n'
|
||||
FROM log
|
||||
WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;
|
||||
|
||||
-- Find the name of each columns
|
||||
SELECT `COLUMN_NAME`
|
||||
FROM `information_schema`.`COLUMNS`
|
||||
WHERE `TABLE_SCHEMA` = 'hobby' AND `TABLE_NAME` = 'log';
|
||||
|
||||
-- Add the column names to the heading of the file
|
||||
SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage'
|
||||
UNION ALL
|
||||
SELECT * FROM log
|
||||
WHERE
|
||||
DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30
|
||||
INTO OUTFILE 'C:/Temp/oldlogs5.csv'
|
||||
FIELDS ENCLOSED BY ''
|
||||
TERMINATED BY ','
|
||||
ESCAPED BY '"'
|
||||
LINES TERMINATED BY '\r\n';
|
||||
|
||||
|
||||
show columns from log;
|
||||
|
||||
SELECT COLUMN_NAME FROM information_schema.COLUMNS;
|
||||
|
||||
|
||||
-- Remove logs from the table
|
||||
|
||||
SELECT DATEDIFF('2021-08-07 23:00:00', current_timestamp);
|
||||
Loading…
Reference in New Issue
Block a user