<html>
<body>
<%
'Βιβλιοθήκη συναρτήσεων

'IIf Function
Function IIf(i,j,k)
    If i Then IIf = j Else IIf = k
End Function


'Σύνδεση με βάση δεδομένων
connString = "Provider=Sqloledb; User ID=blueskytv; Password=eth27188!); Initial Catalog=blueskytv;Data Source=localhost\sqlexpress;"

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open connString

'Άνοιγμα αρχείου
fileToImport = "program.csv"

Set FSO = Server.Createobject("Scripting.FileSystemObject")
Set objFile = FSO.OpenTextFile(Server.MapPath(fileToImport))

'Ανάγνωση και παράκαμψη της πρώτης γραμμής με τα headers
strLine= objFile.ReadLine

strQ = "DELETE FROM program WHERE channelId = 1;"
Set objRS = objConn.Execute(strQ)

Do Until objFile.AtEndOfStream
	
	strLine= objFile.ReadLine

	'Αντικατάσταση μονού quote με διπλό
	strLine = Replace(strLine,"'","''")

	'Read the first line of the csv, typically these are colum headings
	fields = Split(strLine,";")
	
	'Εισαγωγή στον πίνακα του προγράμματος
	strQ = "INSERT INTO program (channelId, programDay, programDate, programRepeat, propernessId, programTitle,  programDescription, programPhoto, programTrailer, programURL) "

	strQ = strQ & " VALUES (" & Trim(fields(0)) & ", " & Trim(fields(2)) & ", '"  & "1/1/1900 " & Trim(fields(4)) & "', " & IIf(Trim(fields(6)) = "Ε","1","0") & ", " & Trim(fields(7)) & ", '" & Trim(fields(5)) & "', '" & Trim(fields(8)) & "', '" & Trim(fields(9)) & "', '" & Trim(fields(10)) & "', '" & Trim(fields(11)) & "');"
	

	Response.Write strQ & "<br>"


	Set objRS = objConn.Execute(strQ)

	

Loop

objFile.Close
objConn.Close
Set objFile = Nothing
Set objRS = Nothing
Set objConn = Nothing
%>
</body>
</html>