asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0
/****Function Lib By Hutia********************
    This function lib is writen by hutia.
    Version 2.17
    Build on 28/11/2005
**********************************************/
/****Function List************************
    
Packed functions:
DB
    adCmdText, addColumn, alterTable, createTable, dropColumn, dropTable, execSQL,
    getFieldName, getRecordset, getRecordsetEx, getTableName, openDatabase,
*********************************************/
//***packed in the variable DB****
var DB =
{
    adCmdText:1,
    
    addColumn:
        function(tableName,fieldName,conn,typeName){
            if(isEmpty(typeName)){typeName=" Text";}
            strSQL="Alter Table ["+tableName+"] Add ["+fieldName+"] "+typeName;
        
            execSQL(strSQL,conn);
        },
    
    alterTable:
        function(strAlterTableStructure,conn){
            //strAlterTableStructure should in this Form:
            /*tableName {ADD {COLUMN field type[(size)] [NOT NULL] [CONSTRAINT index] |
                ALTER COLUMN field type[(size)] |
                CONSTRAINT multifieldindex} |
                DROP {COLUMN field I CONSTRAINT indexname} }
            */
            strSQL="Alter Table "+strAlterTableStructure;
            execSQL(strSQL,conn);
        },
        
    createTable:
        function(strTableStructure,conn){
            //strTableStructure should in this Form:
            /*tableName ( $fieldName fieldType [(size)]  [NOT NULL]
             [CONSTRAINT index] [WITH COMPRESSION | WITH COMP] [index1]
             [, field2 type [(size)] [NOT NULL] [index2] [, ...]]
             [, CONSTRAINT multifieldindex [, ...]]))
            */
            strSQL="Create Table "+strTableStructure;
            execSQL(strSQL,conn);
            
        },
        
    dropColumn:
        function(tableName,fieldName,conn){
            strSQL="Alter Table "+tableName+" Drop COLUMN ["+fieldName+"] ";
            execSQL(strSQL,conn);
        },
        
    dropTable:
        function(tableName,conn){
            strSQL="Drop Table "+strTableStructure;
            execSQL(strSQL,conn);
        },
        
    execSQL:
        function(strSQLCommand,conn){
            try{
                var sqlCommand=new ActiveXObject("ADODB.Command");
                with(sqlCommand){
                    CommandText=strSQLCommand;
                    CommandType=adCmdText;
                    Prepared=false;
                    ActiveConnection=conn;
                }
                return(sqlCommand.Execute());            
            }catch(e){handError(e,"execSQL");}
        },
        
    getFieldName:
        function(conn,tableName){
            var oRSSchema=new ActiveXObject("ADODB.Recordset");
            var ret="";
        
            if(isNull(conn)){return(false);}
        
            try{
            
            oRSSchema=conn.openSchema(4);
            oRSSchema.movefirst();
        
            while(!oRSSchema.EOF){
                if(oRSSchema("TABLE_NAME")==tableName){
                    ret+=oRSSchema("COLUMN_NAME")+"\n";
                }
                oRSSchema.movenext();
            }
            oRSSchema.Close();
            return(ret);
            }catch(e){handError(e,"getFieldName");return(false);}
        },
        
    getRecordset:
        function(strSQL,strDBPath,PageSize,PageNo){
            if(isNull(strSQL)){return(false);}
            if(isNaN(PageSize)){PageSize=20;}
            if(isNaN(PageNo)){PageNo=1;}
        
            var oRecordset=new ActiveXObject("ADODB.Recordset");
        
            var conn=this.openDatabase(strDBPath);
            if(!conn){alert("Can not open database file !");return(false);}
        
            try{
                oRecordset.open(strSQL,conn,1);
                if(oRecordset.EOF){return(false);}
                oRecordset.PageSize=PageSize;
                oRecordset.AbsolutePage=PageNo;
                return(oRecordset);
            }catch(e){handError(e,"GetRecordset");return(false);}
        },
    getRecordsetEx:
        function(strSQL,strDBPath){
            if(isNull(strSQL)){return(false);}
        
            var oRecordset=new ActiveXObject("ADODB.Recordset");
        
            var conn=this.openDatabase(strDBPath);
            if(!conn){alert("Can not open database file !");return(false);}
        
            try{
                oRecordset.open(strSQL,conn);
                return(oRecordset);
            }catch(e){handError(e,"GetRecordset");return(false);}
        },
        
    getTableName:
        function(conn){
            var oRSSchema=new ActiveXObject("ADODB.Recordset");
            var ret="";
        
            if(isNull(conn)){return(false);}
        
            try{
            
            oRSSchema=conn.openSchema(20);
            oRSSchema.movefirst();
        
            while(!oRSSchema.EOF){
                if(oRSSchema("TABLE_TYPE")=="TABLE"){
                    ret+=oRSSchema("TABLE_NAME")+"\n";
                }
                oRSSchema.movenext();
            }
            oRSSchema.Close();
            return(ret);
            }catch(e){handError(e,"GetTableName");return(false);}
        },
        
    openDatabase:
        function(strDBPath,strDBPass){
            conn=new ActiveXObject("ADODB.Connection");
        
            if(isNull(strDBPath)){strDBPath=DEFAULT_DATA_FILE;}
        
            var strProvider="Provider=Microsoft.Jet.OLEDB.4.0;"
            var strDBPath="Data Source=" +strDBPath+";"
            
            if(!isEmpty(strDBPass)){
                strDBPass="Jet OLEDB:Database Password="+strDBPass+";";
            }else{
                strDBPass="";
            }
            var strConn=strProvider+strDBPath+strDBPass;
        
            try{
                conn.Open(strConn,"","");
                return(conn);
            }catch(e){handError(e,"OpenDataBase");return(false);}
        }
};
posted on 2007-06-06 00:58 汪杰 阅读(247) 评论(0)  编辑 收藏 引用 所属分类: javascript
只有注册用户登录后才能发表评论。

<2006年8月>
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 466814
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜