26
2019.2

获取字段与表名

作者: POPASP
在POPASP中无需在模型类里面手动定义数据表的字段,系统会在模型首次实例化的时候自动获取数据表的字段信息(而且只需要一次,以后会永久缓存字段信息,除非设置不缓存或者删除),如果是调试模式则不会生成字段缓存文件,则表示每次都会重新获取数据表字段信息。 如果想获取某个表(前提是存在该表)的字段信息,可以通过`getTableFields`方法 ```brush:vb dim dict set dict = B_("content").getTableFields("content") '返回的是Dictionary对象 ``` 比如iaspcms中的数据表iAspCms_Content得到的字段如下: ```brush:html { "ContentID": 3, "LanguageID": 3, "SortID": 3, "GroupID": 3, "Exclusive": 202, "Title": 202, "Title2": 202, "Author": 202, "TitleColor": 202, "IsOutLink": 3, "OutLink": 202, "ContentSource": 202, "ContentTag": 203, "Content": 203, "ContentStatus": 3, "IsTop": 3, "IsRecommend": 3, "IsImageNews": 3, "IsHeadline": 3, "IsFeatured": 3, "IsNoComment": 3, "ContentOrder": 3, "IsGenerated": 3, "Visits": 3, "Star": 3, "AddTime": 7, "EditTime": 7, "ImagePath": 203, "IndexImage": 203, "DownURL": 203, "PageTitle": 203, "PageKeywords": 203, "PageDesc": 203, "PageFileName": 203, "Timeing": 7, "TimeStatus": 3, "p_price": 202, "DownGroupID": 202, "VideoGroupID": 202, "ThumbPath": 203 } ``` 其中键是字段名,值是数据类型。 字段缓存保存在Runtime/Data/ 目录下面,缓存机制是每个模型对应一个字段缓存文件(而并非每个数据表对应一个字段缓存文件),命名格式较为复杂,其好处是别人一般不会访问到该文件。 比如Nav模型,文件内容为 ``` fields:ContentID:3 fields:LanguageID:3 fields:SortID:3 fields:GroupID:3 fields:Exclusive:202 fields:Title:202 fields:Title2:202 fields:Author:202 fields:TitleColor:202 fields:IsOutLink:3 fields:OutLink:202 fields:ContentSource:202 fields:ContentTag:203 fields:Content:203 fields:ContentStatus:3 fields:IsTop:3 fields:IsRecommend:3 fields:IsImageNews:3 fields:IsHeadline:3 fields:IsFeatured:3 fields:IsNoComment:3 fields:ContentOrder:3 fields:IsGenerated:3 fields:Visits:3 fields:Star:3 fields:AddTime:7 fields:EditTime:7 fields:ImagePath:203 fields:IndexImage:203 fields:DownURL:203 fields:PageTitle:203 fields:PageKeywords:203 fields:PageDesc:203 fields:PageFileName:203 fields:Timeing:7 fields:TimeStatus:3 fields:p_price:202 fields:DownGroupID:202 fields:VideoGroupID:202 fields:ThumbPath:203 prikey:ContentID ``` 获取数据库的所有表名,可以通过`getTables`来获取,返回的也是Dictionary对象。 所有表名,也被缓存到了文件中,在`Runtime/Data`文件夹下。比如: ```brush:vb iaspcms_adv,iaspcms_apply,iaspcms_comments,iaspcms_config,iaspcms_configgroup,iaspcms_content,iaspcms_custom,iaspcms_data,iaspcms_formset,iaspcms_guestbook,iaspcms_htmlpath,iaspcms_keywords,iaspcms_labels,iaspcms_language,iaspcms_links,iaspcms_menu,iaspcms_mood,iaspcms_order,iaspcms_order2,iaspcms_orderproduct,iaspcms_scene,iaspcms_sort,iaspcms_specset,iaspcms_tabset,iaspcms_tag,iaspcms_user,iaspcms_usergroup,iaspcms_visits,iaspcms_weupload ```