CCFlow之耦合(一)
安装CCFlow就不说了,照着安装文件做,基本上没有大的问题:http://bbs.ccflow.org/showtopic-54.aspx 好不容易配置好了,开始耦合吧 按照Documents目录下的 驰骋工作流引擎-流程设计器操作手册.docx 文件中的 2.6 您的系统与ccFlow组织结构表耦合(集成) 的说明,意思是删除CCFlow中的Port_Station,Port_Dept,Port_Emp,Port_EmpStation,Port_EmpDept这五张表,再建立相对应的同样名字的五个视图就可以了 意思说得很明白了吧 可是知易行难呀 Port_Station(岗位表),这个我们系统里没有,怎么办呢?在CCFlow里的表生成Create脚本,修改一下 use 数据库名 改成我们自己的系统数据库 Port_Dept(部门表),这个问题来了,我们并没有使用CCFlow的那种部门编码方式,没办法改造我们的系统吧,加个部门编码字段:OrgBianHao,修改相关代码,让系统新加的部门可以生成编码。 Port_Emp(人员表),需要(No编号,Name名称, Pass密码, FK_Dept所在部门编号, SID登陆安全ID),这个因为我们用的是部门表的ID,而不是编码,所以要新加一个字段OrgBianHao来存储相关的部门编码,我们的密码是加密的,所以~~,加个字段存储明文密码,SID也没有,这个也加上。这里我用的是,No用的是用户名,Name用的是真实姓名. Port_EmpStation 这个我们系统没有,照建一个就是了 Port_EmpDept 这个简单,从我们的人员表取用户ID和部门编号两个字段放进去就好了 这其中发生了两次ccflow耦合问题:无法更改 'XXX',因为它不是表。的问题 一次是:ccflow耦合问题:无法更改 'Port_Emp',因为它不是表。 这个问题在帖子中解决了,是因为少个字段。 再一次是在点 设置 的时候又报: 无法更改 'Port_EmpDept',因为它不是表。 后来经朋哥指点,原来是因为FK_Emp是整形的问题,把这个字段转换成字符串型的,OK,进去是没问题了。 要完全看起来像是一个系统,这样还不行,得继续改,研究去了,完了再和大家分享。 http://www.cnblogs.com/muyou/archive/2012/08/23/2652525.html
View Detailsccflow数据库结构说明(三)
3, ccflow 流程运行数据表. 【WF_GenerFH : 分合流信息注册表,对于是分合流的流程才有效,发起一条分合流,就多一条数据在此。】 [FID]主键,表ID ,[Title] 标题 ,[GroupKey] 分组主键 ,[FK_Flow] 流程编号, 外键:对应物理表:WF_Flow,表描述:流程编号(流程表中的流程编号) ,[ToEmpsMsg] 接受人员 ,[FK_Node] 停留节点 ,[WFState]状态 ,[RDT] 记录日期 【WF_GenerWorkFlow : 流程注册表(启动一个流程后,就产生一条数据,放在WF_GenerWorkFlow)】 [WorkID]主键,表ID ,[FID] 流程ID ,[FK_FlowSort] 流程类别 ,[FK_Flow] 流程编号, 外键:对应物理表:WF_Flow,表描述:流程编号(流程表中的流程编号) ,[FlowName] 流程名称 ,[Title] 标题(如:总经理室-zhoupeng,周朋在2012-04-19 00:38发起.) ,[WFState] 流程状态 ,[Rec] 发起人 ,[RecName] 发起人名称 ,[RDT] 记录日期 ,[FK_Node] 节点, 主外键:对应物理表:WF_Node,表描述:节点 ,[NodeName] 节点名称 ,[FK_Dept] 部门, 主外键:对应物理表:Port_Dept,表描述:部门 ,[DeptName] 部门名称 【WF_GenerWorkerlist : 节点工作人员表.( 发送一个步骤后,就把接受的工作人员放入WF_GenerWorkerlist,流程运行完成后此记录就被删除了) 】 [WorkID]主键,表ID ,[FK_Emp] 人员编号, 主外键:对应物理表:Port_Emp,表描述:用户 ,[FK_EmpText]名称 ,[FK_Node] […]
View Detailsccflow数据库结构说明(二)
2, ccflow流程规则描述表. 用来存储流程配置的基础信息。 以 WF_ 开头. 列举如下: 【WF_FlowSort : 流程类别表.】 【No】关键字 类型编号 【Name】类型名称 【IDX】顺序 数据类型: 【WF_Flow : 流程表.】 [No]关键字 流程编号 ,[FK_FlowSort]流程类别, 外键:对应物理表:WF_FlowSort,表描述:流程类别(流程类别表中的类型编号) ,[Name] 流程名称 ,[IsOK]是否起用 ,[FlowRunWay]运行方式,枚举类型:0 手工启动;1 指定人员按时启动;2 数据集按时启动;3 触发式启动; ,[RunObj]运行内容 ,[IsCanStart]可以独立启动否?(独立启动的流程可以显示在发起流程列表里) ,[Note]备注 ,[StartListUrl]导航Url ,[AppType]流程应用类型(正常、工程类等) ,[DocType]公文类型(对公文有效),枚举类型:0 正式公文;1 便函; ,[XWType]行文类型(对公文有效),枚举类型:0 上行文;1 平行文;2 下行文; ,[FlowType]流程类型 ,[FlowSheetType]表单类型 ,[RunSQL]流程结束执行后执行的SQL ,[NumOfBill]是否有单据 ,[NumOfDtl]是否有关联表 […]
View Detailsccflow数据库结构说明(一)
整理人:路华金 前言: ccflow 有自动修复数据表功能,所以表的字段的变化不需要用户干预由ccflow自动完成。所以如果你看到sql的错误,在执行一般就可以解决,如果解决不了,就执行一次数据库修复工具。 ccflow 有自动增加字段备注功能,所以每个字段的中文名称都已经增加了数据表的字段的备注属性上了,请注意对照,以方便您阅读ccflow。 了解ccflow 的表结构是您二次开发的基础,所以ccflow的高级用户需要熟悉每个表,掌握必要的表结构. 但是没有必要全部掌握。 ccflow 表命名规则是 前缀+"_"+表名. 大多以英文缩写或者,拼音大写组成. 比如: Port_Emp 人员表.、WF_Flow 流程表。 一个流程就有一个流程ID,叫OID。 数据表 ccflow 表分为框架表、流程规则描述表、流程数据运行表、公共表4大类: 1.框架表: 通常以Sys_ 与 Port_ 开头. 也可以称为ccflow系统表. 它是存储系统运行的基础信息. 没有必要多了解它们. 列举如下: Port_Emp: 操作员表. Port_Station: 岗位表 Port_Dept: 部门表 Port_EmpStation: 人员岗位表. Port_EmpDept: 人员部门对应表. Port_Unit: 集团公司表,对于集团类的用户有效. 【WF_Node】节点名称修改表(节点名称修改后保存的物理表) [NO]节点编号 [NAME] 节点名称 【Sys_MapData:】映射主表——新建流程或节点表、表单表、从表信息(只要要新建一张表的,都会在此出现),会在此表插入一条记录 [No]主键,值=相应物理表的表名 [Name] 描述(如节点就节点名称,流程就流程名称) [EnPK] 实体主键 [SearchKeys] 查询键 [PTable] 物理表(值=相应物理表的表名) [Dtls] 明细表(从表) [DBURL] [Tag] [FrmType] 表单类型 [FK_FrmSort] 表单类别 [AttrsInTable] 在表格中显示的列 [AppType] 应用类型 [Designer] 设计者 [DesignerUnit] 单位 [DesignerContact] 联系方式 [FK_Flow] 流程表单属性:FK_Flow [FormType] 流程表单属性:表单类型,枚举类型:0 傻瓜表单;1 自由表单;2 自定义表单;3 SDK表单;9 禁用(对多表单流程有效); [URL] 流程表单属性:Url [FrmW] 表单宽度 […]
View Details解决Warning: Cannot modify header information – headers alread
方法一:在PHP里Cookie的使用是有一些限制的。1、使用setcookie必须在<html>标签之前2、使用setcookie之前,不可以使用echo输入内容3、直到网页被加载完后,cookie才会出现4、setcookie必须放到任何资料输出浏览器前,才送出…..由于上面的限制,在使用setcookie()函数时,学会遇到 "Undefined index"、"Cannot modify header information – headers already sent by"…等问题,解决办法是在输出内容之前,产生cookie,可以在程序的最上方加入函数 ob_start();ob_start :打开输出缓冲区函数格式:void ob_start(void)说明:当缓冲区激活时,所有来自PHP程序的非文件头信息均不会发送,而是保存在内部缓冲区。为了输出缓冲区的内容,可以使用ob_end_flush()或flush()输出缓冲区的内容。方法二:解 决Warning: Cannot modify header information – headers already sent by …… 前几天装了个php的大头贴系统测试,发现报错Warning: Cannot modify header information – headers already sent by ……今天又装openads,还是出现这个问题。怒了。上网找了半天,有人说要在文件开头写上ob_start();失败。后来打开 php.ini 然后把 output_buffering 设为 on 。重起appache,OK。看来这才是解决办法。特别注意:(我就是看了这个才解决问题的)如果使用utf-8编码,一定要去掉UTF-8中的BOM,这都是因为utf-8编码文件含有的bom原因,而php4,5都是不支持bom的。去掉bom,可以用Notepad++打开转换一下。(我就是看了这个才解决问题的)用PHP的ob_start(); 控制您的浏览器cache 。 http://www.wangzhanxiugai.com/article-46.html
View DetailsIIS配置PHP5.3配置完成后—FastCGI Error14001 (0x800736b1)___解决方法
IIS配置PHP5.3配置完成后—FastCGI Error14001 (0x800736b1)___解决方法2010-12-23 0:41 服务器环境: PHP版本:php-5.3.0-Win32-VC9-x86.zip WIN2003 IIS6 按照前一篇的教程[IIS上安装PHP5.3的方法(教程) ]安装PHP 5.3 安装好后还是提示如下错误: FastCGI ErrorThe FastCGI Handler was unable to process the request. ——————————————————————————-- Error Details: Error Number: 14001 (0x800736b1). Error Description: 由于应用程序配置不正确,应用程序未能启动。重新安装应用程序可能会纠正这个问题。 HTTP Error 500 – Server Error.Internet Information Services (IIS) 发生此错误的关键原因在于没有安装VC9运行库 即VISUAL C++ 2008 Microsoft Visual C++ 2008 Redistributable Package (x86)下载地址: http://www.microsoft.com/downloads/details.aspx?FamilyID=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=zh-cn 安装后即能正常使用了. 相关日志JTBC(php版):FLASH幻灯片完美调用方法如何阻止putty变成inactiveJTBC(php版):折腾了我三天的问题终于解决了,一个字“爽”!JTBC(php版):错误Deprecated: Function split() is deprecated in解决方法PHP:错误 Deprecated: Function split() is deprecated in … 解决办法 转自:http://hi.baidu.com/taotaoi/item/064515d8e4cb4de854347f93
View DetailsLucene
Lucene是apache软件基金会4 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,即它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎,部分文本分析引擎(英文与德文两种西方语言)。Lucene的目的是为软件开发人员提供一个简单易用的工具包,以方便的在目标系统中实现全文检索的功能,或者是以此为基础建立起完整的全文检索引擎。 简介 Lucene是一套用于全文检索和搜寻的开源程式库,由Apache软件基金会支持和提供。Lucene提供了一个简单却强大的应用程式接口,能够做全文索引和搜寻。在Java开发环境里Lucene是一个成熟的免费开源工具。就其本身而言,Lucene是目前以及最近几年最受欢迎的免费Java资讯检索程式库。人们经常提到资讯检索程式库,虽然与搜寻引擎有关,但不应该将资讯检索程式库与搜索引擎相混淆。[1] 历史 Lucene最初是由Doug Cutting开发的,在SourceForge的网站上提供下载。在2001年9月做为高质量的开源Java产品加入到Apache软件基金会的 Jakarta家族中。随着每个版本的发布,这个项目得到明显的增强,也吸引了更多的用户和开发人员。2004年7月,Lucene1.4版正式发布,10月的1.4.2版本做了一次bug修正。表1.1显示了Lucene的发布历史。 版本 0.01 2000年3月 第一个开源版本(SourceForge) 1.0 2000年10月 1.01b 2001年7月 最后的SourceForge版本 1.2 2002年6月 第一个Apache Jakarta版本 1.3 2003年12月 复合索引格式,查询分析器增加,远程搜索,token定位,可扩展的API 1.4 2004年7月 Sorting, span queries, term vectors 1.4.1 2004年8月 排序性能的bug修正 1.4.2 2004年10月 IndexSearcher optimization and misc. fixes 1.4.3 2004年冬 Misc. fixes2.4.1 2009年3月8日发布新版本 2.3.0 2008年1月 更新为2.3.0 2.4.0 2008年10月 更新为2.4.0 2.4.1 2009年 5月 更新为 2.4.1 2.9.0 2009年9月25号 更新为2.9.0 2.9.1 2009年11月6号 更新为2.9.1 3.0.0 2009年11月25号 更新为3.0.0 3.0.1 2010年2月26号 更新为3.0.1 3.0.2 2010年6月18号 更新为3.0.2 3.0.3 2010年12月3号 更新为3.0.3 3.3.0 2011年7月初 更新为3.3.0 3.4.0 2011年9月14日 更新为3.4.0 3.5.0 2011年11月26日 更新为3.5.0 3.5.0 2012年4月12日更新为3.6.0 3.6.1 2012年7月23日更新为3.6.1 […]
View DetailsHTML 5 Web SQL Database初探
【51CTO译文】在《从零开始构建HTML 5页面》一文中,我们了解到HTML 5的一些新增特性并通过实例打造了一个完整的HTML 5页面。但HTML 5标准不只局限于传统的标记语言,它还拥有很多让人期待的API接口,利用这些接口,开发者可以创建更加丰富、更加引人注目的应用程序。之前我们介绍过支持文件拖放上传功能的HTML 5 File API,今天,我们一起来了解HTML 5的Web SQL Database API,使用本地和会话存储实现简单的对象持久化。 对于HTML 5,也许最为有用的就是它新推出的“Web Storage”(Web 存储)API。对简单的关键值对(比如应用程序设置)或简单对象(如应用程序状态)进行存储,使用本地和会话存储能够很好地完成,但是在对琐碎的关系数据进行处理之外,它就力所不及了。而这正是 HTML 5 的“Web SQL Database”API 接口的应用所在。 先提个醒,该文下面的内容需要读者对 JavaScript 和面对对象编程(尤其是匿名内的内部函数)以及SQL具有很好的理解。 打开链接 为了打开一个连接,我们执行以下代码:
1 |
<ol class="dp-sql" style="padding:5px 0px;color:#5c5c5c;list-style-position:initial;list-style-image:initial;word-wrap:break-word;word-break:normal;border:none;background-color:#f7f7f7;margin-top:0px !important;margin-right:0px !important;margin-bottom:1px !important;margin-left:55px;"><li class="alt" style="margin:0px !important;padding:0px 3px 0px 10px !important;color:inherit;list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"><span style="margin:0px;padding:0px;border:none;background-color:inherit;">db = openDatabase(</span><span class="string" style="margin:0px;padding:0px;border:none;color:blue;background-color:inherit;">"ToDo"</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">, </span><span class="string" style="margin:0px;padding:0px;border:none;color:blue;background-color:inherit;">"0.1"</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">, </span><span class="string" style="margin:0px;padding:0px;border:none;color:blue;background-color:inherit;">"A list of to do items."</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">, 200000); </span></span></p></li></ol> |
以上代码创建了一个数据库对象 db,名称是 Todo,版本编号为0.1。db 还带有描述信息和大概的大小值。用户代理(user agent)可使用这个描述与用户进行交流,说明数据库是用来做什么的。利用代码中提供的大小值,用户代理可以为内容留出足够的存储。如果需要,这个大小是可以改变的,所以没有必要预先假设允许用户使用多少空间。 为了检测之前创建的连接是否成功,你可以检查那个数据库对象是否为null:
1 |
<ol class="dp-xml" style="padding:5px 0px;color:#5c5c5c;list-style-position:initial;list-style-image:initial;word-wrap:break-word;word-break:normal;border:none;background-color:#f7f7f7;margin-top:0px !important;margin-right:0px !important;margin-bottom:1px !important;margin-left:55px;"><li class="alt" style="margin:0px !important;padding:0px 3px 0px 10px !important;color:inherit;list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;">if(!db) </span></p></li><li style="list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;margin:0px !important;padding:0px 3px 0px 10px !important;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"> alert("Failed to connect to database."); </span></p></li></ol> |
绝不可以假设该连接已经成功建立,即使过去对于某个用户它是成功的。为什么一个连接会失败,存在多个原因。也许用户代理出于安全原因拒绝你的访问,也许设备存储有限。面对活跃而快速进化的潜在用户代理,对用户的机器、软件及其能力作出假设是非常不明智的行为。比如,当用户使用手持设备时,他们可自由处置的数据可能只有几兆字节。 执行查询 执行一个查询,你可以使用database.transaction()函数。该函数具有单一参数,负责查询实际执行的函数。 该函数(通常是匿名的)具有一个类型事务的参数。
1 |
<ol class="dp-sql" style="padding:5px 0px;color:#5c5c5c;list-style-position:initial;list-style-image:initial;word-wrap:break-word;word-break:normal;border:none;background-color:#f7f7f7;margin-top:0px !important;margin-right:0px !important;margin-bottom:1px !important;margin-left:55px;"><li class="alt" style="margin:0px !important;padding:0px 3px 0px 10px !important;color:inherit;list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"><span style="margin:0px;padding:0px;border:none;background-color:inherit;">db.</span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">transaction</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">( </span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">function</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">(tx) { </span></span></p></li></ol> |
该事务具有一个函数:executeSql。这个函数使用四个参数:表示查询的字符串,插入到查询中问号所在处的字符串数据(很像 Java 的预先准备好的语句),一个成功时执行的函数和一个失败时执行的函数。
1 |
<ol class="dp-sql" style="padding:5px 0px;color:#5c5c5c;list-style-position:initial;list-style-image:initial;word-wrap:break-word;word-break:normal;border:none;background-color:#f7f7f7;margin-top:0px !important;margin-right:0px !important;margin-bottom:1px !important;margin-left:55px;"><li class="alt" style="margin:0px !important;padding:0px 3px 0px 10px !important;color:inherit;list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"><span style="margin:0px;padding:0px;border:none;background-color:inherit;">tx.executeSql(</span><span class="string" style="margin:0px;padding:0px;border:none;color:blue;background-color:inherit;">"SELECT COUNT(*) FROM ToDo"</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">, [], </span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">function</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">(result){}, </span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">function</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">(tx, error){}); </span></span></p></li><li class="alt" style="margin:0px !important;padding:0px 3px 0px 10px !important;color:inherit;list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"><br style="clear:both;width:0px;height:0px;" /><br style="clear:both;width:0px;height:0px;" /><br style="clear:both;width:0px;height:0px;" /><br style="clear:both;width:0px;height:0px;" /></span></p></li></ol><p style="padding:0px;background-color:transparent;text-indent:28px;margin-top:10px;margin-bottom:10px;"><br /></p><p style="padding:0px;background-color:transparent;text-indent:28px;margin-top:10px;margin-bottom:10px;"><br /></p><p style="padding:0px;background-color:transparent;text-indent:28px;margin-top:10px;margin-bottom:10px;"><br /></p><p style="padding:0px;background-color:transparent;text-indent:28px;margin-top:10px;margin-bottom:10px;"><br /></p><p style="padding:0px;background-color:transparent;text-indent:28px;margin-top:10px;margin-bottom:10px;"><br /></p><p style="padding:0px;background-color:transparent;text-indent:28px;margin-top:10px;margin-bottom:10px;"><br /></p> |
查询成功时 当查询成功执行时,应用程序跳转至一个具有一对参数的查询,一个是 transaction,另一个是它搜集的 results。对于实际上将你的数据传递至用户,这是非常完美的,比如显示 ToDo 列表。有关这个话题后面再讲。 查询失败失败时 当查询没能执行时执行。由于你将 transaction 对象作为函数的第一个参数进行传递,当出现错误时你可以继续执行查询。例如,如果是因为缺少表格(table)而查询无法运行,这是创建一个表格并在此执行该语句的绝佳时机。从该函数的第二个参数,你可以获得有关该错误的信息(包括描述)。 示例 假设我们想要使用上面的例子,想要查询数据库中的某个表格,如果该表格不存在,我们就创建一个表格。 在这个示例中,我们将调用具有一个函数参数的 db.transaction()。这个参数中,我们调用 tx.executeSql()。如果这个步骤成功,我们不做任何操作(因此是一个null参数)。或者我们将该事务和执行失败的函数一起传递,并再次调用 tx.executeSql()。这一次使用创建查询。
1 |
<ol class="dp-sql" style="padding:5px 0px;color:#5c5c5c;list-style-position:initial;list-style-image:initial;word-wrap:break-word;word-break:normal;border:none;background-color:#f7f7f7;margin-top:0px !important;margin-right:0px !important;margin-bottom:1px !important;margin-left:55px;"><li class="alt" style="margin:0px !important;padding:0px 3px 0px 10px !important;color:inherit;list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"><span style="margin:0px;padding:0px;border:none;background-color:inherit;">db.</span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">transaction</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">( </span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">function</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">(tx) { tx.executeSql(</span><span class="string" style="margin:0px;padding:0px;border:none;color:blue;background-color:inherit;">"SELECT COUNT(*) FROM ToDo"</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">,<br style="clear:both;width:0px;height:0px;" /> [], </span><span class="op" style="margin:0px;padding:0px;border:none;color:#808080;background-color:inherit;">null</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">, </span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">function</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">(tx, error) { tx.executeSql(</span><span class="string" style="margin:0px;padding:0px;border:none;color:blue;background-color:inherit;">"CREATE TABLE ToDo (id REAL UNIQUE, label TEXT, timestamp REAL)"</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">,<br style="clear:both;width:0px;height:0px;" /> [], </span><span class="op" style="margin:0px;padding:0px;border:none;color:#808080;background-color:inherit;">null</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">, </span><span class="op" style="margin:0px;padding:0px;border:none;color:#808080;background-color:inherit;">null</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">); } ); } ); </span></span></p></li><li class="alt" style="margin:0px !important;padding:0px 3px 0px 10px !important;color:inherit;list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p> </p></li></ol> |
使用所有这些内部方法,可能有点麻烦,所以你也许想在外部创建一个调用 db.transaction() 的函数。比如,我们可以让错误函数是自包含的,并将其命名为“createToDoTable()”。 插入 为了让代码更加简洁和安全,Web SQL Database API 允许你为 transaction.executeSql() 函数提供字符串数据,用以表示调用的 SQL 语句中的变量。我们使用以下的代码进行演示:
1 |
<ol class="dp-sql" style="padding:5px 0px;color:#5c5c5c;list-style-position:initial;list-style-image:initial;word-wrap:break-word;word-break:normal;border:none;background-color:#f7f7f7;margin-top:0px !important;margin-right:0px !important;margin-bottom:1px !important;margin-left:55px;"><li class="alt" style="margin:0px !important;padding:0px 3px 0px 10px !important;color:inherit;list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"><span style="margin:0px;padding:0px;border:none;background-color:inherit;">db.</span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">transaction</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">( </span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">function</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">(tx) { tx.executeSql(</span><span class="string" style="margin:0px;padding:0px;border:none;color:blue;background-color:inherit;">"INSERT INTO ToDo (label, timestamp) values(?, ?)"</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">, <br style="clear:both;width:0px;height:0px;" />[label, new </span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">Date</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">().getTime()], </span><span class="op" style="margin:0px;padding:0px;border:none;color:#808080;background-color:inherit;">null</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">, </span><span class="op" style="margin:0px;padding:0px;border:none;color:#808080;background-color:inherit;">null</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">); } ); </span></span></p></li><li class="alt" style="margin:0px !important;padding:0px 3px 0px 10px !important;color:inherit;list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p> </p></li></ol> |
在这个示例中,第一个参数中的两个问号将被后面数组中对应的项替代。第一个是为该任务设置的标签(也许是我们之前在代码中定义的一个变量),以及调用函数生成的时间戳。 执行该查询,其结果与下面语句类似:
1 |
<ol class="dp-sql" style="padding:5px 0px;color:#5c5c5c;list-style-position:initial;list-style-image:initial;word-wrap:break-word;word-break:normal;border:none;background-color:#f7f7f7;margin-top:0px !important;margin-right:0px !important;margin-bottom:1px !important;margin-left:55px;"><li class="alt" style="margin:0px !important;padding:0px 3px 0px 10px !important;color:inherit;list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">INSERT</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;"> </span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">INTO</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;"> ToDo (label, </span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">timestamp</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">) </span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">values</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;"> (</span><span class="string" style="margin:0px;padding:0px;border:none;color:blue;background-color:inherit;">"Test"</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">, 1265925077487) </span></span></p></li></ol> |
对结果进行处理 成功执行的函数对结果对象包含集合或行。每一列表示一个结果。该结果包含分配给它的一组值,表示该特定结果的数据库中的每一列的值。通过调用 result.rows.item(i) 可以访问一个行,其中 i 是你想要查询的行的指针。想要从一行中选择一个值,你可以传递给该行一个数组格式的字符串指针,它表示你需要查询的列。例如,如果想要标签(label)列,我们可以调用 row['label']。 以下代码使用结果对象来输出一个查询的结果:
1 |
<ol class="dp-sql" style="padding:5px 0px;color:#5c5c5c;list-style-position:initial;list-style-image:initial;word-wrap:break-word;word-break:normal;border:none;background-color:#f7f7f7;margin-top:0px !important;margin-right:0px !important;margin-bottom:1px !important;margin-left:55px;"><li class="alt" style="margin:0px !important;padding:0px 3px 0px 10px !important;color:inherit;list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"><span style="margin:0px;padding:0px;border:none;background-color:inherit;">db.</span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">transaction</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">( </span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">function</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">(tx) { tx.executeSql(</span><span class="string" style="margin:0px;padding:0px;border:none;color:blue;background-color:inherit;">"SELECT * FROM ToDo"</span><span style="margin:0px;padding:0px;border:none;background-color:inherit;">, [], </span></span></p></li><li style="list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;margin:0px !important;padding:0px 3px 0px 10px !important;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"> </span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">function</span><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;">(tx, result) { </span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">for</span><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;">(var i = 0; i < result.</span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">rows</span><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;">.length; i++) </span></p></li><li class="alt" style="margin:0px !important;padding:0px 3px 0px 10px !important;color:inherit;list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;">{ document.write(</span><span class="string" style="margin:0px;padding:0px;border:none;color:blue;background-color:inherit;">'<b>'</span><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"> + result.</span><span class="keyword" style="margin:0px;padding:0px;border:none;color:#006699;background-color:inherit;font-weight:bold;">rows</span><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;">.item(i)[</span><span class="string" style="margin:0px;padding:0px;border:none;color:blue;background-color:inherit;">'label'</span><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;">] + </span><span class="string" style="margin:0px;padding:0px;border:none;color:blue;background-color:inherit;">'</b><br />'</span><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;">); } }, </span><span class="op" style="margin:0px;padding:0px;border:none;color:#808080;background-color:inherit;">null</span><span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;">); } ); </span></p></li><li class="alt" style="margin:0px !important;padding:0px 3px 0px 10px !important;color:inherit;list-style:none;word-wrap:break-word;word-break:normal;border:none;background-image:url(http://images.51cto.com/images/art1105/images/0.gif);background-attachment:scroll;background-color:transparent;line-height:18px;background-position:-498px -70px;background-repeat:no-repeat repeat;"><p><br /></p></li></ol> |
结论 […]
View DetailsSmarty
Smarty是一个使用PHP写出来的模板引擎,是目前业界最著名的PHP模板引擎之一。它分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PHP代码逻辑分离。简单的讲,目的就是要使PHP程序员同前端人员分离,使程序员改变程序的逻辑内容不会影响到前端人员的页面设计,前端人员重新修改页面不会影响到程序的程序逻辑,这在多人合作的项目中显的尤为重要。 定义 如何使我的PHP脚本从设计中独立出来?这无疑地是在PHP邮件列表上所提问的最多的问题之一。虽然PHP被标榜为“HTML嵌入式语言”,在写过许多PHP和HTML混合式的工程之后,我产生了一个分离表单和内容的想法。而且,在许多公司里规划设计者的角色和程序设计者是分开的。于是,这样的一个模板解决方案产生了…… 例如在一个公司,一个应用程序的开发流程如下:在提交计划文档之后,界面设计者[美工]制作了网站的外观模型,然后把它交给后台程序员。程序员使用PHP实现商业逻辑,同时使用外观模型做成基本架构。然后工程被返回到HTML页面设计者继续完善。就这样工程可能在后台程序员和页面设计者之间来来回回好几次。由于后台程序员不喜欢干预任何有关HTML标签,同时也不需要美工们和PHP代码混在一起;美工设计者只需要配置文件,动态区块和其他的界面部分,不必要去接触那些错综复杂的PHP代码。因此,这时候有一个很好的模板支持就显得很重要了。 纵观现今存在的许多PHP模板解决方案(比如PHPLIB),大多数都只是提供了用模板取代变量和将动态区块的功能有限的格式化的基本方法。但是我们的需求比这个要高的多。我们完全不想要PHP程序员去设计HTML页面,可是这又是不可避免的。例如:如果美工想要在动态区块之间交替不同的背景颜色,他就可能得和程序员预先说好。同样,美工们也应该有自己对于页面设计的配置文件,这同样可以通过变量把他们拉到模板里边去 优点 1. 速度:采用Smarty编写的程序可以获得最大速度的提高,这一点是相对于其它的模板引擎技术而言的。 2. 编译型:采用Smarty编写的程序在运行时要编译成一个非模板技术的PHP文件,这个文件采用了PHP与HTML混合的方式,在下一次访问模板时将WEB请求直接转换到这个文件中,而不再进行模板重新编译(在源程序没有改动的情况下) 3. 缓存技术:Smarty选用的一种缓存技术,它可以将用户最终看到的HTML文件缓存成一个静态的HTML页,当设定Smarty的cache属性为true时,在Smarty设定的cachetime期内将用户的WEB请求直接转换到这个静态的HTML文件中来,这相当于调用一个静态的HTML文件。 4. 插件技术:Smarty可以自定义插件。插件实际就是一些自定义的函数。 5. 模板中可以使用if/elseif/else/endif。在模板文件使用判断语句可以非常方便的对模板进行格式重排。 不适合使用Smarty的地方 需要实时更新的内容。例如像股票显示,它需要经常对数据进行更新,这类型的程序使用smarty会使模板处理速度变慢。 小项目。小项目因为项目简单而美工与程序员兼于一人的项目,使用Smarty会在一定程度上丧失PHP开发迅速的优点。 (PS:不过为了整个项目的规范,请大家尝试去使用模板引擎。其实习惯了,开发速度会更加快,以上是没有用习惯模板引擎的开发者遇到的问题) 诞生过程 早在1999年后期,我们就已经开始为模板引擎写说明文档。在完成这个文档之后,我们开始用C写一个模板引擎,并有希望被包含到PHP里去。在 撞上了许多的技术难题的同时,“什么是模板应该做的,什么不该做”这个问题,也被热烈的讨论着。从这些经验,我们决定应该用PHP将模板引擎写成一个类,让任何觉得合适的人使用它。所以我们写了一个引擎,从此就有了Smarty。(注:这个类以前从来没有公开发表过)。这个类几乎达到了我们所有的要求:常规变量替换,支持包括其他模板,使用配置文件集成设置,嵌入PHP代码,限制'if'语句的作用,还有更多的可以多层嵌套的健壮的动态区块。它用常规表达式做到这一切,于是代码变得相当令人费解。在每次调用的时候,都要去解析那些语法和常规表达式,于是在大型应用的时候,它显然慢了下来。在程序员的眼光看来,最大的问题还是使用PHP脚本建立和处理模板和动态区块的所有必要工作。我们应该如何使他变得更简单? 我们可以想象Smarty应该有怎样的最后表现。我们知道PHP代码如果没有了模板解析的开销将有多快,我们也知道从一般的美工看来PHP语言是多么的“恐怖”,然而这一切可以被一种更简单的模板语法掩饰掉。我们应该怎样把这两种方法的长处结合起来? 于是,Smarty诞生了……
View DetailsVelocity
Velocity是一个基于java的模板引擎(template engine)。它允许任何人仅仅简单的使用模板语言(template language)来引用由java代码定义的对象。 应用 当Velocity应用于web开发时,界面设计人员可以和java程序开发人员同步开发一个遵循MVC架构的web站点,也就是说,页面设计人员可以只关注页面的显示效果,而由java程序开发人员关注业务逻辑编码。Velocity将java代码从web页面中分离出来,这样为web站点的长期维护提供了便利,同时也为我们在JSP和PHP之外又提供了一种可选的方案。 更多功能 Velocity的能力远不止web站点开发这个领域,例如,它可以从模板(template)产生SQL和PostScript、XML,它也可以被当作一个独立工具来产生源代码和报告,或者作为其他系统的集成组件使用。Velocity也可以为Turbine web开发架构提供模板服务(template service)。Velocity+Turbine提供一个模板服务的方式允许一个web应用以一个真正的MVC模型进行开发。 http://baike.baidu.com/view/77351.htm
View Details