commit
74be5c5c9b
@ -16,9 +16,9 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||
bool WriteData(string cmd);
|
||||
|
||||
//Method for deleteing data from a data source, 0 for successful
|
||||
bool DeleteData();
|
||||
bool DeleteData(string cmd);
|
||||
|
||||
// Method for updating data from a data source, 0 for sucessful
|
||||
bool UpdateData();
|
||||
bool UpdateData(string cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,27 +16,40 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||
|
||||
//public SQLSource(string info)
|
||||
//{
|
||||
// conn = new SqlConnection(info);
|
||||
// // Do I put using here to make sure the connection closed once the object is gone?
|
||||
// conn = new SqlConnection(info);
|
||||
// // Perhaps open the connection here?
|
||||
// // conn.Open();
|
||||
//}
|
||||
|
||||
public bool DeleteData()
|
||||
// The also Identical to update data, maybe only one method is enough
|
||||
public bool DeleteData(string cmd)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// Makre sure to Check for instanceof() before casting to a SQLReader in the controller
|
||||
public Object ReadData(string cmd)
|
||||
{
|
||||
try
|
||||
{
|
||||
// conn.open();
|
||||
//conn.Open();
|
||||
//SqlCommand command = new SqlCommand(null, conn);
|
||||
//SqlCommand command = new SqlCommand(cmd, conn);
|
||||
|
||||
// conn.Execute();
|
||||
Console.WriteLine("Access a SQL database");
|
||||
Console.WriteLine("Select * from archive");
|
||||
|
||||
// Execute the command to query the data
|
||||
//using SqlDataReader sqlReader = command.ExecuteReader();
|
||||
|
||||
// while (myReader)
|
||||
// Print to console
|
||||
// conn.close();
|
||||
return null;
|
||||
//conn.Close();
|
||||
//conn.Dispose();
|
||||
//return sqlReader;
|
||||
return new SqlConnection();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -45,11 +58,31 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpdateData()
|
||||
// TODO: No idea how to check if the command is valid or where to check it
|
||||
public bool UpdateData(string cmd)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
try
|
||||
{
|
||||
//conn.Open();
|
||||
|
||||
// Create the SQL command object
|
||||
//SqlCommand command = new SqlCommand(cmd, conn);
|
||||
|
||||
// Execute the command to change the rows in a table
|
||||
//command.ExecuteNonQuery();
|
||||
|
||||
//conn.Close();
|
||||
//conn.Dispose();
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Very similar to UpdataData if not identical
|
||||
public bool WriteData(string cmd)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@ -81,9 +114,9 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||
origFile.CopyTo(compressor);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -92,5 +125,28 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||
}
|
||||
}
|
||||
|
||||
//public Object ReadPreparedStmt(string table){
|
||||
// //conn.Open();
|
||||
// //SqlCommand command = new SqlCommand(null, conn);
|
||||
// SqlCommand command = new SqlCommand("SELECT * from @table;", conn);
|
||||
// SqlParameter tableParam = new SqlParameter("@table", System.Data.SqlDbType.Text, 50);
|
||||
|
||||
// tableParam.Value = table;
|
||||
// command.Parameters.Add(tableParam);
|
||||
|
||||
// // conn.Execute();
|
||||
// Console.WriteLine("Access a SQL database");
|
||||
// Console.WriteLine("Select * from archive");
|
||||
|
||||
// // Make the Prepare statement and excute the query:
|
||||
// command.Prepare();
|
||||
// SqlDataReader sqlReader = command.ExecuteReader();
|
||||
|
||||
// // while (myReader)
|
||||
// // Print to console
|
||||
// // conn.close();
|
||||
// return sqlReader;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,53 +10,23 @@ 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);
|
||||
|
||||
Console.WriteLine("File Name: {0}", fileInfo.FullName);
|
||||
|
||||
//Console.WriteLine("Starting file compression: ");
|
||||
//Compress(fileInfo);
|
||||
//Console.WriteLine("Ending compression");
|
||||
//SqlConnection myconn = new SqlConnection();
|
||||
|
||||
|
||||
//IDataSource dataSource = new SQLSource();
|
||||
|
||||
SQLSource sqlSource = new SQLSource();
|
||||
bool res = sqlSource.CompressFile(fileName);
|
||||
//bool res = CompressFile(fileName);
|
||||
Console.WriteLine(res);
|
||||
|
||||
Console.WriteLine(CreateFileName());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void Compress(FileInfo fi)
|
||||
|
||||
public static string CreateFileName()
|
||||
{
|
||||
// Get the stream of the source file.
|
||||
using (FileStream inFile = fi.OpenRead())
|
||||
{
|
||||
// Prevent compressing hidden and
|
||||
// already compressed files.
|
||||
if ((File.GetAttributes(fi.FullName) & FileAttributes.Hidden) != FileAttributes.Hidden & fi.Extension != ".gz")
|
||||
{
|
||||
// Create the compressed file.
|
||||
using (FileStream outFile =
|
||||
File.Create(fi.FullName + ".gz"))
|
||||
{
|
||||
using (GZipStream Compress = new GZipStream(outFile, CompressionMode.Compress))
|
||||
{
|
||||
// Copy the source file into
|
||||
// the compression stream.
|
||||
inFile.CopyTo(Compress);
|
||||
|
||||
Console.WriteLine("Compressed {0} from {1} to {2} bytes.",
|
||||
fi.Name, fi.Length.ToString(), outFile.Length.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return DateTime.Now.ToString() + "archive.txt";
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
12
Source Code/TeamHobby.Main/text.cs
Normal file
12
Source Code/TeamHobby.Main/text.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TeamHobby.Main
|
||||
{
|
||||
internal class text
|
||||
{
|
||||
}
|
||||
}
|
||||
BIN
doc/LowLevel/ArchivingWithError.png
Normal file
BIN
doc/LowLevel/ArchivingWithError.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 544 KiB |
1
doc/LowLevel/ArchivingWithError.svg
Normal file
1
doc/LowLevel/ArchivingWithError.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 92 KiB |
146
doc/LowLevel/ArchivingWithError.txt
Normal file
146
doc/LowLevel/ArchivingWithError.txt
Normal file
@ -0,0 +1,146 @@
|
||||
|
||||
title Use Case: Archiving
|
||||
|
||||
participant Controller.cs #90EE90
|
||||
participant RDSFactory #26abff
|
||||
participant ArchiveManager #ffffe0
|
||||
participant SqlDAO #D3D3D3
|
||||
participant MariaDB #00FFFF
|
||||
|
||||
activate Controller.cs #90EE90
|
||||
// Create a new factory
|
||||
Controller.cs->RDSFactory:factory = new RDSFactory()
|
||||
activate RDSFactory #26abff
|
||||
RDSFactory->RDSFactory:Constructor()
|
||||
Controller.cs<--RDSFactory:return RDSFactory
|
||||
deactivate RDSFactory
|
||||
Controller.cs->SqlDAO: ++IDataSource factory.GetDataSource(string name, string connInfo)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlDAO:++Constructor(string connInfo)++
|
||||
Controller.cs<--SqlDAO: ++return SqlDAO++
|
||||
|
||||
|
||||
alt #red
|
||||
SqlDAO ->SqlDAO: Catch Exception
|
||||
SqlDAO -->Controller.cs:return "DataSourceTimeOut"
|
||||
end
|
||||
deactivate SqlDAO
|
||||
|
||||
// Create Archive Manager
|
||||
|
||||
activate ArchiveManager #ffffe0
|
||||
group #lightblue Connection to DataSource successful
|
||||
Controller.cs ->ArchiveManager:new ArchiveManager(IDataSource conn)
|
||||
ArchiveManager ->ArchiveManager: ArchiveManager(IDatasSource conn)
|
||||
|
||||
// Calling the main:
|
||||
ArchiveManager -->Controller.cs: return ArchiveManager
|
||||
loop #lightblue while true
|
||||
alt #lightgreen The First Day of the month at 00:00:00 AM
|
||||
Controller.cs ->ArchiveManager: bool ArchiveManager.Controller( )
|
||||
|
||||
// Keep looping
|
||||
|
||||
// Check if the directory exist or not
|
||||
alt #lightgreen Archive folder does not exist already in the current directory
|
||||
ArchiveManager -> ArchiveManager:bool CreateArchiveFolder(string path)
|
||||
|
||||
end
|
||||
// Create the file name
|
||||
ArchiveManager ->ArchiveManager:string filePath = string CreateOutFileName( )
|
||||
ArchiveManager ->SqlDAO:bool Compress(string filePath)
|
||||
|
||||
activate SqlDAO #D3D3D3
|
||||
activate MariaDB #00FFFF
|
||||
SqlDAO ->MariaDB: bool CopyToArchive(string filePath)
|
||||
// Sql Command to add data to the table
|
||||
MariaDB ->MariaDB: SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage' \nUNION ALL\nSELECT * FROM log\nWHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30\nINTO OUTFILE @filePath\nFIELDS ENCLOSED BY ''\nTERMINATED BY ','\nESCAPED BY '"'\nLINES TERMINATED BY '\r\\n';
|
||||
alt #lightgreen No error when doing executing copy SQL command
|
||||
MariaDB --> SqlDAO: return True
|
||||
SqlDAO -->ArchiveManager: return True
|
||||
end
|
||||
|
||||
alt #red Error occur when executing copy SQL command on Database
|
||||
MariaDB -->SqlDAO: throw SQLException
|
||||
deactivate MariaDB
|
||||
SqlDAO -->ArchiveManager: throw SqlException
|
||||
deactivate SqlDAO
|
||||
|
||||
|
||||
ArchiveManager ->ArchiveManager: Catch Exception
|
||||
// Removing created files if the process failed
|
||||
alt #red Log output text file exist
|
||||
ArchiveManager ->ArchiveManager: File.Delete(string filePath)
|
||||
end
|
||||
alt #red Compressed file exist
|
||||
ArchiveManager ->ArchiveManager: File.Delete(string comFilePath)
|
||||
end
|
||||
end
|
||||
|
||||
activate SqlDAO #D3D3D3
|
||||
// Compress the file
|
||||
SqlDAO ->SqlDAO: bool CompressArchive(string filePath)
|
||||
alt #lightgreen File Compression was successful
|
||||
SqlDAO -->ArchiveManager: return True
|
||||
end
|
||||
alt #red File Compresssion failed
|
||||
SqlDAO -->ArchiveManager: throw FileException
|
||||
ArchiveManager ->ArchiveManager: Catch Exception
|
||||
alt #red Log output text file exist
|
||||
ArchiveManager ->ArchiveManager: File.Delete(filePath)
|
||||
end
|
||||
alt #red Compressed file exist
|
||||
ArchiveManager ->ArchiveManager: File.Delete(string comFilePath)
|
||||
end
|
||||
end
|
||||
// Remove output file
|
||||
SqlDAO ->SqlDAO:bool RemoveOutputFile(string filePath)
|
||||
alt #lightgreen UncompressFile was removed successfully
|
||||
SqlDAO -->ArchiveManager: return true
|
||||
end
|
||||
|
||||
alt #red Uncompressfile failed to be removed
|
||||
SqlDAO -->ArchiveManager: throw FileException
|
||||
deactivate SqlDAO
|
||||
ArchiveManager ->ArchiveManager: catch Exception
|
||||
|
||||
alt #red Log output text file exist
|
||||
ArchiveManager ->ArchiveManager: File.Delete(string filePath)
|
||||
end
|
||||
alt #red Compressed file exist
|
||||
ArchiveManager ->ArchiveManager: File.Delete(string comFilePath)
|
||||
end
|
||||
end
|
||||
|
||||
activate SqlDAO #D3D3D3
|
||||
activate MariaDB #00FFFF
|
||||
SqlDAO ->MariaDB: bool RemoveEntries( )
|
||||
MariaDB ->MariaDB: DELETE from log \nWHERE \nDATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;
|
||||
|
||||
alt #lightgreen No error when doing executing remove old logs SQL command
|
||||
MariaDB-->SqlDAO:return True
|
||||
SqlDAO -->ArchiveManager: return True
|
||||
end
|
||||
|
||||
alt #red Error occur when executing removing SQL command on Database
|
||||
MariaDB -->SqlDAO: throw SQLException
|
||||
deactivate MariaDB
|
||||
SqlDAO-->ArchiveManager: throw SQLException
|
||||
deactivate SqlDAO
|
||||
ArchiveManager ->ArchiveManager:Catch Exception
|
||||
alt #red Log output text file exist
|
||||
ArchiveManager ->ArchiveManager: File.Delete(string filePath)
|
||||
end
|
||||
alt #red Compressed file exist
|
||||
ArchiveManager ->ArchiveManager: File.Delete(string comFilePath)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
ArchiveManager --> Controller.cs:return True
|
||||
deactivate ArchiveManager
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
BIN
doc/LowLevel/ArchivingWithSingleton.pdf
Normal file
BIN
doc/LowLevel/ArchivingWithSingleton.pdf
Normal file
Binary file not shown.
99
doc/LowLevel/ArchvingMasterCon.txt
Normal file
99
doc/LowLevel/ArchvingMasterCon.txt
Normal file
@ -0,0 +1,99 @@
|
||||
|
||||
title Use Case: Archiving
|
||||
|
||||
participant Controller.cs #90EE90
|
||||
participant RDSFactory #26abff
|
||||
participant ArchiveManager #ffffe0
|
||||
participant SqlDAO #D3D3D3
|
||||
participant MariaDB
|
||||
|
||||
activate Controller.cs
|
||||
// Create a new factory
|
||||
Controller.cs->RDSFactory:factory = new RDSFactory()
|
||||
activate RDSFactory #26abff
|
||||
RDSFactory->RDSFactory:Constructor()
|
||||
Controller.cs<--RDSFactory:return RDSFactory
|
||||
deactivate RDSFactory
|
||||
Controller.cs->SqlDAO: ++IDataSource factory.GetDataSource(string name, string connInfo)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlDAO:++Constructor(string connInfo)++
|
||||
Controller.cs<--SqlDAO: ++return SqlDAO++
|
||||
deactivate SqlDAO
|
||||
|
||||
// Create Archive Manager
|
||||
activate ArchiveManager
|
||||
Controller.cs ->ArchiveManager:new ArchiveManager(IDataSource conn)
|
||||
ArchiveManager ->ArchiveManager: ArchiveManager(IDatasSource conn)
|
||||
|
||||
// Calling the main:
|
||||
ArchiveManager -->Controller.cs: return ArchiveManager
|
||||
Controller.cs ->ArchiveManager: bool ArchiveManager.Controller( )
|
||||
|
||||
// Keep looping
|
||||
|
||||
loop #lightblue while true
|
||||
alt #lightgreen The First Day of the month at 00:00:00 AM
|
||||
// Check if the directory exist or not
|
||||
alt #lightgreen Archive folder does not exist already in the current directory
|
||||
ArchiveManager -> ArchiveManager:int CreateArchiveFolder(string path)
|
||||
|
||||
end
|
||||
// Create the file name
|
||||
ArchiveManager ->ArchiveManager: string filePath = string CreateFileName( )
|
||||
ArchiveManager ->SqlDAO:bool Compress(string filePath)
|
||||
|
||||
activate SqlDAO
|
||||
activate MariaDB
|
||||
SqlDAO ->MariaDB: bool CopyToArchive(string filePath)
|
||||
alt #red No error when doing executing copy SQL command
|
||||
MariaDB --> SqlDAO: return True
|
||||
|
||||
else #red Error occur when executing copy SQL command on Database
|
||||
MariaDB -->SqlDAO: throw SQLException
|
||||
deactivate MariaDB
|
||||
SqlDAO -->ArchiveManager: throw SqlException
|
||||
deactivate SqlDAO
|
||||
|
||||
ArchiveManager ->ArchiveManager: Catch SqlException
|
||||
end
|
||||
|
||||
activate SqlDAO
|
||||
// Compress the file
|
||||
SqlDAO ->SqlDAO: bool CompressArchive(string filePath)
|
||||
// Remove output file
|
||||
SqlDAO ->SqlDAO:bool RemoveOutputFile(string filePath)
|
||||
alt #red File was created succesffuly
|
||||
SqlDAO -->SqlDAO: new file
|
||||
else File Exception
|
||||
SqlDAO ->SqlDAO: Catch FileException
|
||||
SqlDAO -->ArchiveManager: throw FileException
|
||||
deactivate SqlDAO
|
||||
ArchiveManager ->ArchiveManager: catch FileException
|
||||
end
|
||||
|
||||
activate SqlDAO
|
||||
|
||||
SqlDAO ->MariaDB: bool RemoveEntries( )
|
||||
activate MariaDB
|
||||
alt #red No error when doing executing remove old logs SQL command
|
||||
MariaDB-->SqlDAO:return True
|
||||
|
||||
|
||||
else Error occur when executing removing SQL command on Database
|
||||
MariaDB -->SqlDAO: throw SQLException
|
||||
deactivate MariaDB
|
||||
SqlDAO-->ArchiveManager: throw SQLException
|
||||
deactivate SqlDAO
|
||||
ArchiveManager ->ArchiveManager:Catch SqlException
|
||||
end
|
||||
activate SqlDAO
|
||||
SqlDAO-->ArchiveManager:return True
|
||||
deactivate SqlDAO
|
||||
end
|
||||
|
||||
|
||||
deactivate MariaDB
|
||||
|
||||
end
|
||||
deactivate ArchiveManager
|
||||
deactivate SqlDAO
|
||||
BIN
doc/LowLevel/UMLforArchving.png
Normal file
BIN
doc/LowLevel/UMLforArchving.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
BIN
doc/LowLevel/archivingMasterCon.pdf
Normal file
BIN
doc/LowLevel/archivingMasterCon.pdf
Normal file
Binary file not shown.
BIN
doc/LowLevel/arcvhingMasterCon.pdf
Normal file
BIN
doc/LowLevel/arcvhingMasterCon.pdf
Normal file
Binary file not shown.
64
src/dbCode/ExportingRows.txt
Normal file
64
src/dbCode/ExportingRows.txt
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
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';
|
||||
|
||||
-- Remove old logs from the log table
|
||||
DELETE from log where DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;
|
||||
|
||||
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