Javascript database connectorjsdbc: Provides JavaScript to effectively connect to the database. Currently, MySQL, SQLite, and access are supported. More databases will be supported later; engineers engaged in Ajax development certainly want to have a component that connects to the database directly through Ajax, which saves many background operation steps, such as eliminating the need to deploy the Java Runtime Environment, without writing a lot of complicated JDBC calls, jsdbc can be well integrated into your application, regardless of the debugging needs or application needs.
/**
* Class description: This script is mainly used to connect to jsdbc for SQLite, so that you can directly use SQLite in Js.
* Event creation:
*/
// Include OCX object
Document. writeln ("<Object ID = 'sqlite 'classid = 'clsid: 901af4f3-5381-4e1b-a8bf-bf914cffe569 '");
Document. writeln ("codebase = 'jsdbc _ SQLite. ocx # version = 0,000 '");
Document. writeln ("width = '0' Height = '0'> ");
Document. writeln ("</Object> ");
// Error message
VaR lasterr = "";
// Exec falg
VaR execflag;
/**
* Connecte to SQLite Server
* Provite: SQLite IP, port, DB name, user, password, charset
*/
Function connectsqlite ()
{
Execflag = SQLite. connecte ("D: // personaldocs // oursoft // jsdbc // test_sqlite.db ");
If (execflag = 1)
Return 1;
Else
{
Lasterr = SQLite. getlasterror ();
Return 0;
}
}
/**
* Close already open connection
*/
Function closesqlite ()
{
Execflag = SQLite. Close ();
If (execflag = 1)
Return 1;
Else
{
Lasterr = SQLite. getlasterror ();
Return 0;
}
}
/**
* Exec insert into SQL statement
* @ Param {object} SQL
*/
Function insertsqlite (SQL)
{
Execflag = SQLite. insertdata (SQL );
If (execflag = 1)
Return 1;
Else
{
Lasterr = SQLite. getlasterror ();
Return 0;
}
}
/**
* Exec Database Manager Language
* @ Param {object} SQL
*/
Function execdmlsqlite (SQL)
{
Execflag = sqlite.exe cdml (SQL );
If (execflag = 1)
Return 0;
Else
{
Lasterr = SQLite. getlasterror ();
Return 0;
}
}
/**
* Exec select data from database
* @ Param {object} SQL
* @ Param {object} cnum = number of fields in SQL statement
*/
Function selectsqlite (SQL, cnum)
{
VaR rs = SQLite. selectdata (SQL, cnum );
If (Rs. length> 0)
{
VaR array = new array ();
VaR dataset = new array ();
VaR rowsplit = ''; // row interval. Note that this is not a normal '-', but a conversion from 0x06. You can copy it when using it.
VaR fieldspinterval = ''; // field interval. Note that this is not a normal '|', but is converted from 0x05. You can copy it when using it.
Array = Rs. Split (rowsplit );
For (VAR I = 0; I <array. length; I ++)
{
VaR datarow = array [I]. Split (fieldspow );
Dataset [I] = datarow;
}
Return dataset;
}
Else
{
Lasterr = SQLite. getlasterror ();
Return NULL;
}
}
/**
* Exec Delete SQL statement
* @ Param {object} SQL
*/
Function deletesqlite (SQL)
{
Execflag = SQLite. deletedata (SQL );
If (execflag = 1)
Return 1;
Else
{
Lasterr = SQLite. getlasterror ();
Return 0;
}
}
/**
* Exec update SQL statement
* @ Param {object} SQL
*/
Function updatesqlite (SQL)
{
Execflag = SQLite. updatedata (SQL );
If (execflag = 1)
Return 1;
Else
{
Lasterr = SQLite. getlasterror ();
Return 0;
}
}
/**
* Exec transcation
* @ Param {object} SQL
*/
Function exectranscationsqlite (SQL)
{
Execflag = sqlite.exe ctranscation (SQL );
If (execflag = 1)
Return 1;
Else
{
Lasterr = SQLite. getlasterror ();
Return 0;
}
}
/**
* Get last error message if exec error from JS
*/
Function getlasterrorsqlite ()
{
Return lasterr;
}