Upload. aspx:
<% @ LANGUAGE = 'javascript '%>
<! -- # Include file = "../adojvs. inc" -->
<! -- # Include file = "../conn. inc" -->
<%
// Execute the SQL statement
// 2012-12-6 Gu Laicheng
Function RunSQL (MySQL)
{
Var ret = "";
Var rs1 = Server. CreateObject ("ADODB. Recordset ");
Rs1.CursorType = adOpenKeyset;
Rs1.LockType = adLockBatchOptimistic;
// Response. Write ("<br/>" + MySQL + "");
Try {
Rs1.Open (MySQL, conn );
}
Catch (ex ){
Var ErrStr, ErrStr0, ErrStr1 = "=>" + new Date () + "<br/> ";
ErrStr0 = "Error:" + ex + "<br/>" + MySQL;
Var o = conn. Errors;
For (var I = 0; I <o. Count; I ++)
{
ErrStr1 + = o. item (I ). number + ":" + o. item (I ). description + "," + o. item (I ). SQLState + ";" + o. item (I ). source;
}
ErrStr = ErrStr0 + "<br/>" + ErrStr1;
O. Clear ();
Response. Write ("<br/>" + ErrStr + "");
}
If (rs1.State = 1)
{
If (! (Rs1.BOF & rs1.EOF ))
{
Ret = rs1 (0). value;
}
Rs1.Close ();
}
Return ret;
}
Var Class = {
Create: function (){
Return function (n ){
This. initialize. apply (this, arguments );
}
}
}
Var TABLE = Class. create ();
TABLE. prototype = {
Initialize: function (TabName ){
This. TabName = TabName;
This. Fields = [];
This. FieldCount = 0;
This. values = [];
This. types = [];
This. MySQL = "";
This. flag;
},
F: function (s)
{
Var a = s. split (",");
For (var I = 1; I <a. length; I ++)
{
This. Fields [I-1] = a [I];
}
This. FieldCount = a. length-1;
},
V: function (s)
{
Var a = s. split (",");
This. flag = a [0];
For (var I = 1; I <a. length; I ++)
{
This. value[ I-1] = a [I];
}
If (a [0] = 1) this. Replace ();
If (a [0] = 2) this. Insert ();
If (a [0] = 3) this. Update ();
If (a [0] = 4) this. Delete ();
},
Replace: function ()
{
If (this. values [0] = 0)
This. Insert ();
Else
This. Update ();
},
Insert: function ()
{
Var fs = "", vs = "";
Var j = 0; // I, j may not be synchronized, and some column values may be empty, indicating that their values are not inserted. Make sure that the SQL syntax is correct.
For (var I = 0; I <this. FieldCount; I ++)
{
If (this. values [I] = "NULL") continue;
If (j = 0)
{
Fs + = this. Fields [I];
Vs + = "'" + this. values [I] + "'";
} Else
{
Fs + = "," + this. Fields [I];
Vs + = ", '" + this. values [I] + "'";
}
J ++;
}
This. MySQL = "insert into" + this. TabName + "(" + fs + ") values (" + vs + ")";
},
Update: function ()
{
This. MySQL = "update" + this. TabName + "set ";
For (var I = 1; I <this. FieldCount; I ++)
{
If (this. values [I] = "NULL ")
{
If (I! = 1) this. MySQL + = ",";
This. MySQL + = this. Fields [I] + "= null ";
} Else
{
If (I! = 1) this. MySQL + = ",";
This. MySQL + = this. Fields [I] + "= '" + this. values [I] + "'";
}
}
This. MySQL + = "where" + this. Fields [0] + "= '" + this. values [0] + "'";
},
Delete: function ()
{
This. MySQL = "delete from" + this. TabName + "where ";
Var j = 0; // I, j may not be synchronized, and some column values may be empty, indicating that it is not used as a condition. Make sure that the SQL syntax is correct.
For (var I = 0; I <this. FieldCount; I ++)
{
If (this. values [I] = "") continue;
If (this. values [I] = "NULL ")
{
If (j! = 0) this. MySQL + = "and ";
This. MySQL + = this. Fields [I] + "is null ";
} Else
{
If (j! = 0) this. MySQL + = "and ";
This. MySQL + = this. Fields [I] + "= '" + this. values [I] + "'";
}
J ++;
}
}
};
Var fso, ts, s;
Var ForReading = 1, ForWriting = 2;
Var name; // = "c: webyafulwisadtt.csv ";
Name = Server. MapPath ("t.csv ");
Var fso = new ActiveXObject ("Scripting. FileSystemObject ");
If (fso. FileExists (name ))
{
Response. Write ("file" + name +! ");
Ts = fso. OpenTextFile (name, ForReading, true );
// Ts. SkipLine ();
Var data = new TABLE (Request. QueryString ("a") + "");
S = ts. ReadLine ();
Data. F (s );
Response. Write ("<br/>" + data. FieldCount );
Response. Write ("<br/>" + s. replace (/,/g, "t") + "");
Response. Write ("<br/>" + data. Fields + "");
While (! Ts. AtEndOfStream)
{
S = ts. ReadLine ();
// Response. Write ("<br/>" + s. replace (/,/g, "t") + "");
Data. V (s );
Response. Write ("<br/>" + data. MySQL + "");
RunSQL (data. MySQL );
}
Ts. Close ();
}
Else
{
Response. Write ("file" + name + "does not exist. Check the file and try again! ");
}
%>