public prikey '表的主键
public tableName '表名
public auto_ '自动填充
public validate_ '自动验证
Public db_type,access_type,db_path,db_host,db_user,db_name,db_pwd,db_prefix
Public patchValidate '是否批处理验证
public [error] '最近错误消息
public pageSize '默认每页取多少条记录
public Version '版本号
Public isOnlySql '是否只获取sql语句
Public tool 'POPASP_DATABASE_TOOL实例
Private options '存储分配过来的参数,Dictionary对象
Private parsedOptions '存储解析后的参数,Dictionary对象
Private lastSql '存储最后一条sql语句,String
Private ConnStr '数据库连接字符串
Private dTables '存储已经取出的所有的数据表
Private dTS '存储数据表的结构,为dTableStructrues的简写
public isTest
Public Function getLastSql()
getLastSql = lastSql
End Function
'获取parsedOptions("data")
'如果使用了db.create,则可以使用getData获取最终过滤或添加后的数据,该数据为一维Dictionary对象
Public Function getData()
if isObject( parsedOptions("data") ) then
set getData = parsedOptions("data")
else
getData = parsedOptions("data")
end if
end Function
' select 查询多条记录
' 与连贯操作相结合使用
' db.select
' db.field().order().where().page().select
' 分页需要使用db.page
Public Function [Select] ()
call parseOptions
lastSql = getSelectSql(parsedOptions)
if isOnlySql then [Select] = lastSql : Exit Function
set [Select] = tool.Select(lastSql,parsedOptions,Me.pageSize)
call ResumeOpts
End Function
' select_map 查询多条记录,并使用回调函数处理
' 与连贯操作相结合使用
' db.select_map( callback )
' db.field().order().where().page().select_map
' 分页需要使用db.page
Public Property Get select_map ( callback )
dim rs
call parseOptions
lastSql = getSelectSql(parsedOptions)
if isOnlySql then [select_map] = lastSql : Exit Property
set rs = tool.Select(lastSql,parsedOptions,Me.pageSize)
do while not rs.eof
Execute( "call " & callback & "(rs)" )
rs.movenext
loop
rs.close : set rs = nothing
call ResumeOpts
End Property
' find 查询一条记录
' 与连贯操作相结合使用
' db.find
' db.field().order().where().position().find
' 逐条显示需要使用db.position
Public Function Find()
call parseOptions
lastSql = getFindSql( parsedOptions )
if isOnlySql then Find = lastSql : Exit Function
set Find = tool.Find( lastSql ,parsedOptions )
call ResumeOpts
End Function
' 根据查询条件,判断是否存在记录
' 与连贯操作相结合使用
' db.RecordExists
' db.field().order().where().position().find
' 逐条显示需要使用db.position
Public Function RecordExists()
dim rs
set rs = Find
if isOnlySql then
RecordExists = Find
else
RecordExists = not rs.eof
end if
Call tool.closeRS(rs)
End Function
' getObject 以实例化类的形式返回一条记录
' 通过find来获取的,将字段名作为属性名
Public Function getObject()
dim rs
if isOnlySql then getObject = Me.find : Exit Function
set rs = Me.find : set getObject = P_("POPASP_SELF_OBJECT").rs2object(rs,isAccess)
Call tool.closeRS(rs)
End Function
' getObject2 以实例化类的形式返回一条记录
' 通过select来获取的,将记录的第一个值作为属性名,将记录第二个值作为值
Public Function getObject2()
dim rs
if isOnlySql then getObject2 = Me.select : Exit Function
set rs = Me.select
set getObject2 = P_("POPASP_SELF_OBJECT").rs2object(rs,isAccess)
Call tool.closeRS(rs)
End Function
'同find,返回一维Dictionary对象
Public Function getRow( )
dim rs
if isOnlySql then getRow = Me.find : Exit Function
set rs = Me.find
set getRow = P_("POPASP_RECORDSET").rs2dict(rs,isAccess)
Call tool.closeRS(rs)
End Function
'获取字符值,如果fields为"",则取field方法fieldRev中的值
'返回数据为Dictionary对象
Public Function getFields(fields)
dim rs
call field( fields )
if isOnlySql then getFields = Me.find : Exit Function
set rs = Me.find : set getFields = P_("POPASP_RECORDSET").rs2dict(rs,isAccess)
Call tool.closeRS(rs)
End Function
'获取一个字段值
'取一个字段的值,如果分配多个,只取第一个,取多个字段的值请使用getRow
Public Function getOne()
dim rs
if isOnlySql then getOne = Me.find : Exit Function
set rs = Me.find
if not rs.BOF and not rs.EOF then
if rs.fields.count > 0 then
getOne = rs.Fields(0).Value
end if
end if
Call tool.closeRS(rs)
End Function
'获取字段值,如果fields为"",则取field方法fieldRev中的值
'取一个字段的值,如果分配多个,只取第一个,取多个字段的值请使用getFields
Public Function getField(fields)
call field( fields )
getField = Me.getOne
End Function
'获取键值对,返回数据为Dictionary对象
'结合field()使用,必须传入两个字段名,第1个为键,第2个为值。
Public Function getKeyValue()
dim rs
if isOnlySql then getKeyValue = Me.Select : Exit Function
set rs = Me.select
set getKeyValue = P_("POPASP_RECORDSET").rs2dict2(rs)
Call tool.closeRS(rs)
End Function
'使用同select,返回二维Dictionary对象,键名为主键值
Public Function getPKAll()
dim rs,bool
if not isEmpty(options("page")) then
bool = 1
else
bool = 0
end if
if isOnlySql then getPKAll = Me.Select : Exit Function
set rs = Me.select
set getPKAll = P_("POPASP_RECORDSET").rs2data(rs,getPK(),isAccess,bool)
Call tool.closeRS(rs)
End Function
'获取二维Dictionary对象
Public Function getAll()
on error resume next
dim rs,dict,bool
if not isEmpty(options("page")) then
bool = 1
else
bool = 0
end if
if isOnlySql then getAll = Me.Select : Exit Function
set rs = Me.select
set dict = P_("POPASP_RECORDSET").rs2data(rs,"",isAccess,bool)
set getAll = dict
Call tool.closeRS(rs)
End Function
'获取二维xml对象
'neednull = 1 则去掉空白,否则保留内容为空的标签
Public Function xml( ByRef packageName , neednull )
on error resume next
dim rs,dict,bool
if isOnlySql then xml = Me.Select : Exit Function
set rs = Me.select
xml = P_("POPASP_RECORDSET").rs2xml(rs,packageName , neednull)
Call tool.closeRS(rs)
End Function
'生成xml文件
Public Function SaveXmlFile( packageName , xmlPath)
dim xmlstr
xmlstr = xml( packageName , true )
xmlstr = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbcrlf & "<root>" & vbcrlf & xmlstr & "</root>"
SaveXmlFile = POP_MVC.file_put_contents_without_bom( xmlPath, xmlstr )
End Function
'getArr,同getAll,返回的是数组(数组内每个元素是Dictionary对象)
Public Function getArr()
dim rs,arr,temp
if isOnlySql then getArr = Me.Select : Exit Function
set rs = [Select]
Do While Not rs.BOF And Not rs.EOF
if rs.fields.count > 1 then
temp = Array()
for i = 0 to rs.fields.count-1
POP_MVC.Arr.Push temp,rs.Fields(i).Value
next
POP_MVC.Arr.Push arr,temp
elseif rs.fields.count = 1 then
POP_MVC.Arr.Push arr,rs.Fields(0).Value
end if
rs.MoveNext
LOOP
Call tool.closeRS(rs)
getArr = arr
End Function
'get1Arr,返回的是一维数组
'只取第一个字段,且只取一页
Public Function get1Arr()
dim rs,arr,j
if isOnlySql then get1Arr = Me.Select : Exit Function
set rs = [Select]
j = 0
arr = Array()
Do While Not rs.BOF And Not rs.EOF
if j = rs.pagesize then exit do
POP_MVC.Arr.Push arr,iif( isnull(rs.Fields(0).Value) , "" , rs.Fields(0).Value)
rs.MoveNext
j =