- 浏览: 1290826 次
- 性别:
- 来自: 江苏
最新评论
-
honey_fansy:
的确,不要自己的支持就说完美支持,我的就不行,别说我的不是fi ...
无js实现text-overflow: ellipsis; 完美支持Firefox -
fanchengfei:
事件长微博,欢迎转发:http://weibo.com/332 ...
《在路上 …》 写代码也需要一点演技 – python2.6 的 class decorator -
blued:
没有报错,但排版效果一点都没有 咋回事。请指教
python排版工具 -
szxiaoli:
耍人呀,效果在哪儿呀
滑动效果 -
accaolei:
这个能监到控子目录吗?,我测试了一下,发现子目录里的文件监控不 ...
windows监控目录改动
书接上文,mDBConn.createStatement可以创建一个sql语句的模板,然后可以传入参数执行.
执行过后在通过reset方法重置它.
这样做的好处是:
"""
If you are doing a statement many times, using a precompiled statement will give you a noticable performance improvement because the SQL query doesn't need to be parsed each time.
"""
?1 在用 bindXXXXXParameter 时对应的位置的 0 , 而 ?2 对应的是 1 ... 以此类推 ... 哎,搞不清楚Moillza那群家伙是怎么想的...
还有一种更直观(也更繁琐的)绑定参数的方法 :myfirstparam .用法如下:
var statement = mDBConn.createStatement("SELECT * FROM foo WHERE a = :myfirstparam AND b > :mysecondparam");
var firstidx = statement.getParameterIndex(":myfirstparam");
statement.bindUTF8StringParameter(firstidx, "hello");
var secondidx = statement.getParameterIndex(":mysecondparam");
statement.bindInt32Parameter(secondidx, 1234);
两种方法是可以混合使用的.
不过还是有局限,像下面这种情况还是自己拼装sql吧,不过小心sql注入:
"""
If you want to use a WHERE clause with an IN ( value-list ) expression, Bindings won't work
var ids = "3,21,72,89";
var sql = "DELETE FROM table WHERE id IN ( "+ ids +" )";
"""
有时候,我们不需要取得sql语句的返回值,那么像下面这样就可以了.
var statement = mDBConn.createStatement("INSERT INTO my_table VALUES (?1)");
statement.bindInt32Parameter(52);
statement.execute();
!!!牢牢记住,用完statement后要reset它,否则后果如下.
Un-reset write statements will keep a lock on the tables and will prevent other statements from accessing it. Un-reset read statements will prevent writes.
这种调用方式可以确保有异常时也可以reset,don't worry about unnecessary resets.
var statement = connection.createStatement(...);
try {
// use the statement...
} finally {
statement.reset();
}
当然如果你用.execute(),它会自动reset的.
如果你想获得刚刚插入数据的id,那么这么玩吧.
var sql = "INSERT INTO contacts_table (number_col, name_col) VALUES (?1, ?2)"
var statement = mDBConn.createStatement(sql);
statement.bindUTF8StringParameter(0, number);
statement.bindUTF8StringParameter(1, name);
statement.execute();
var rowid = mDBConn.lastInsertRowID;//最后一条Insert语句产生的id
还有事务,说实话,我很讨厌sql,更讨厌事务,所以大家还是自己看文档吧,我复制一个演示用法.不过注意一点,由于sqlite是用的文件锁,加了事务会快上很多很多,大概的比例是1个小时=1分钟...这个我是有过惨痛经历的.
var ourTransaction = false;
if (!mDBConn.transactionInProgress) {
ourTransaction = true;
mDBConn.beginTransactionAs(mDBConn.TRANSACTION_DEFERRED);
}
// ... use the connection ...
if (ourTransaction)
mDBConn.commitTransaction();
ok,到此为止,数据库大概操作基本够用了.
吾生也有涯,而知也无涯,以有涯随无涯,殆己!
所以不研究更深入了,现在浏览一下各个对象的接口.
1.
mozIStorageConnection
http://developer.mozilla.org/en/MozIStorageConnection
其中 createFunction 以及相关函数是用来创建sqlite函数的,参见
http://www.sqlite.org/c3ref/create_function.html
这里是sqlite的一些内置函数
http://www.sqlite.org/lang_corefunc.html
http://www.sqlite.org/lang_aggfunc.html
此外,应该是调用函数而不自己在sql创建事务
函数
void close();
mozIStorageStatement createStatement(in AUTF8String aSQLStatement);
void executeSimpleSQL(in AUTF8String aSQLStatement);
boolean tableExists(in AUTF8String aTableName);
boolean indexExists(in AUTF8String aIndexName);
void beginTransaction();
void beginTransactionAs(in PRInt32 transactionType);
void commitTransaction();
void rollbackTransaction();
void createTable(in string aTableName, in string aTableSchema);
aTableName
The name of the table to create; table names may consist of the letters A-Z in either upper or lower case, the underscore, and the digits 0-9. The first character must be a letter.
aTableSchema
The table's schema. This should be specified using the same syntax the CREATE TABLE statement uses. For example: "foo INTEGER, bar STRING".
void createFunction(in AUTF8String aFunctionName, in long aNumArguments, in mozIStorageFunction aFunction);
void createAggregateFunction(in AUTF8String aFunctionName, in long aNumArguments, in mozIStorageAggregateFunction aFunction);
void removeFunction(in AUTF8String aFunctionName);
mozIStorageProgressHandler setProgressHandler(in PRInt32 aGranularity, in mozIStorageProgressHandler aHandler);
mozIStorageProgressHandler removeProgressHandler();
属性
connectionReady boolean Indicates whether or not the connection is open or ready to use. This is false if the
connection failed to open or if it has been closed.
databaseFile nsIFile The current database file. NULL if the database connection refers to an in-memory database.
lastInsertRowID long long The row ID from the last SQL INSERT operation.
lastError long The last sqlite error code that occurred.
lastErrorString AUTF8String The English error string reported by the sqlite library for the last sqlite operation.
schemaVersion long The schema version of the database. This should not be used until the database is ready. The version will be reported as 0 if not set. since Gecko 1.9 M8
transactionInProgress boolean Returns true if there is a transaction in progress on the database; otherwise returns false.
常量
TRANSACTION_DEFERRED 0 Default. The database lock is acquired when needed.
TRANSACTION_IMMEDIATE 1 Get a read lock on the database immediately.
TRANSACTION_EXCLUSIVE 2 Get a write lock on the database immediately.
2.
mozIStorageStatement
函数
mozIStorageStatement clone();
AUTF8String getParameterName(in unsigned long aParamIndex);
unsigned long getParameterIndex(in AUTF8String aName);
AUTF8String getColumnName(in unsigned long aColumnIndex);
unsigned long getColumnIndex(in AUTF8String aName);
void reset();
void bindUTF8StringParameter(in unsigned long aParamIndex, in AUTF8String aValue);
void bindStringParameter(in unsigned long aParamIndex, in AString aValue);
void bindDoubleParameter(in unsigned long aParamIndex, in double aValue);
void bindInt32Parameter(in unsigned long aParamIndex, in long aValue);
void bindInt64Parameter(in unsigned long aParamIndex, in long long aValue);
void bindNullParameter(in unsigned long aParamIndex);
void bindBlobParameter(in unsigned long aParamIndex, [array,const,size_is(aValueSize)] in octet aValue, in unsigned long aValueSize);
void execute();
boolean executeStep();
The reset() method must be called on the statement after the last call of executeStep.
AString escapeStringForLIKE(in AString aValue, in wchar aEscapeChar);
An AString of an escaped version of aValue (%, _ and the escape char are escaped with the escape char).
For example, we will convert "foo/bar_baz%20cheese" into "foo//bar/_baz/%20cheese" (if the escape char is '/').
属性
parameterCount unsigned long Number of parameters.
columnCount unsigned long Number of columns returned.
state long The current state.
常量
Constant Value Description
MOZ_STORAGE_STATEMENT_INVALID 0 The SQL statement is Invalid.
MOZ_STORAGE_STATEMENT_READY 1 The SQL statement is ready to be executed.
MOZ_STORAGE_STATEMENT_EXECUTING 2 The SQL statement is executing at the moment.
3.
mozIStorageValueArray
函数
long getTypeOfIndex(in unsigned long aIndex);
long getInt32(in unsigned long aIndex);
long long getInt64(in unsigned long aIndex);
double getDouble(in unsigned long aIndex);
AUTF8String getUTF8String(in unsigned long aIndex);
AString getString(in unsigned long aIndex);
void getBlob(in unsigned long aIndex, out unsigned long aDataSize, [array,size_is(aDataSize)] out octet aData);
boolean getIsNull(in unsigned long aIndex);
属性
numEntries unsigned long The number of entries in the array (each corresponding to a column in the database row).
常量
Constant Value Description
VALUE_TYPE_NULL 0 Null data type.
VALUE_TYPE_INTEGER 1 INTEGER data type.
VALUE_TYPE_FLOAT 2 FLOAT data type.
VALUE_TYPE_TEXT 3 TEXT data type.
VALUE_TYPE_BLOB 4 BLOB data type.
4.
mozIStorageService
函数
nsIFile backupDatabaseFile(in nsIFile aDBFile, in AString aBackupFileName, [optional] in nsIFile aBackupParentDirectory);
mozIStorageConnection openDatabase(in nsIFile aDatabaseFile);
mozIStorageConnection openSpecialDatabase(in string aStorageKey);
mozIStorageConnection openUnsharedDatabase(in nsIFile aDatabaseFile);
执行过后在通过reset方法重置它.
这样做的好处是:
"""
If you are doing a statement many times, using a precompiled statement will give you a noticable performance improvement because the SQL query doesn't need to be parsed each time.
"""
?1 在用 bindXXXXXParameter 时对应的位置的 0 , 而 ?2 对应的是 1 ... 以此类推 ... 哎,搞不清楚Moillza那群家伙是怎么想的...
还有一种更直观(也更繁琐的)绑定参数的方法 :myfirstparam .用法如下:
var statement = mDBConn.createStatement("SELECT * FROM foo WHERE a = :myfirstparam AND b > :mysecondparam");
var firstidx = statement.getParameterIndex(":myfirstparam");
statement.bindUTF8StringParameter(firstidx, "hello");
var secondidx = statement.getParameterIndex(":mysecondparam");
statement.bindInt32Parameter(secondidx, 1234);
两种方法是可以混合使用的.
不过还是有局限,像下面这种情况还是自己拼装sql吧,不过小心sql注入:
"""
If you want to use a WHERE clause with an IN ( value-list ) expression, Bindings won't work
var ids = "3,21,72,89";
var sql = "DELETE FROM table WHERE id IN ( "+ ids +" )";
"""
有时候,我们不需要取得sql语句的返回值,那么像下面这样就可以了.
var statement = mDBConn.createStatement("INSERT INTO my_table VALUES (?1)");
statement.bindInt32Parameter(52);
statement.execute();
!!!牢牢记住,用完statement后要reset它,否则后果如下.
Un-reset write statements will keep a lock on the tables and will prevent other statements from accessing it. Un-reset read statements will prevent writes.
这种调用方式可以确保有异常时也可以reset,don't worry about unnecessary resets.
var statement = connection.createStatement(...);
try {
// use the statement...
} finally {
statement.reset();
}
当然如果你用.execute(),它会自动reset的.
如果你想获得刚刚插入数据的id,那么这么玩吧.
var sql = "INSERT INTO contacts_table (number_col, name_col) VALUES (?1, ?2)"
var statement = mDBConn.createStatement(sql);
statement.bindUTF8StringParameter(0, number);
statement.bindUTF8StringParameter(1, name);
statement.execute();
var rowid = mDBConn.lastInsertRowID;//最后一条Insert语句产生的id
还有事务,说实话,我很讨厌sql,更讨厌事务,所以大家还是自己看文档吧,我复制一个演示用法.不过注意一点,由于sqlite是用的文件锁,加了事务会快上很多很多,大概的比例是1个小时=1分钟...这个我是有过惨痛经历的.
var ourTransaction = false;
if (!mDBConn.transactionInProgress) {
ourTransaction = true;
mDBConn.beginTransactionAs(mDBConn.TRANSACTION_DEFERRED);
}
// ... use the connection ...
if (ourTransaction)
mDBConn.commitTransaction();
ok,到此为止,数据库大概操作基本够用了.
吾生也有涯,而知也无涯,以有涯随无涯,殆己!
所以不研究更深入了,现在浏览一下各个对象的接口.
1.
mozIStorageConnection
http://developer.mozilla.org/en/MozIStorageConnection
其中 createFunction 以及相关函数是用来创建sqlite函数的,参见
http://www.sqlite.org/c3ref/create_function.html
这里是sqlite的一些内置函数
http://www.sqlite.org/lang_corefunc.html
http://www.sqlite.org/lang_aggfunc.html
此外,应该是调用函数而不自己在sql创建事务
函数
void close();
mozIStorageStatement createStatement(in AUTF8String aSQLStatement);
void executeSimpleSQL(in AUTF8String aSQLStatement);
boolean tableExists(in AUTF8String aTableName);
boolean indexExists(in AUTF8String aIndexName);
void beginTransaction();
void beginTransactionAs(in PRInt32 transactionType);
void commitTransaction();
void rollbackTransaction();
void createTable(in string aTableName, in string aTableSchema);
aTableName
The name of the table to create; table names may consist of the letters A-Z in either upper or lower case, the underscore, and the digits 0-9. The first character must be a letter.
aTableSchema
The table's schema. This should be specified using the same syntax the CREATE TABLE statement uses. For example: "foo INTEGER, bar STRING".
void createFunction(in AUTF8String aFunctionName, in long aNumArguments, in mozIStorageFunction aFunction);
void createAggregateFunction(in AUTF8String aFunctionName, in long aNumArguments, in mozIStorageAggregateFunction aFunction);
void removeFunction(in AUTF8String aFunctionName);
mozIStorageProgressHandler setProgressHandler(in PRInt32 aGranularity, in mozIStorageProgressHandler aHandler);
mozIStorageProgressHandler removeProgressHandler();
属性
connectionReady boolean Indicates whether or not the connection is open or ready to use. This is false if the
connection failed to open or if it has been closed.
databaseFile nsIFile The current database file. NULL if the database connection refers to an in-memory database.
lastInsertRowID long long The row ID from the last SQL INSERT operation.
lastError long The last sqlite error code that occurred.
lastErrorString AUTF8String The English error string reported by the sqlite library for the last sqlite operation.
schemaVersion long The schema version of the database. This should not be used until the database is ready. The version will be reported as 0 if not set. since Gecko 1.9 M8
transactionInProgress boolean Returns true if there is a transaction in progress on the database; otherwise returns false.
常量
TRANSACTION_DEFERRED 0 Default. The database lock is acquired when needed.
TRANSACTION_IMMEDIATE 1 Get a read lock on the database immediately.
TRANSACTION_EXCLUSIVE 2 Get a write lock on the database immediately.
2.
mozIStorageStatement
函数
mozIStorageStatement clone();
AUTF8String getParameterName(in unsigned long aParamIndex);
unsigned long getParameterIndex(in AUTF8String aName);
AUTF8String getColumnName(in unsigned long aColumnIndex);
unsigned long getColumnIndex(in AUTF8String aName);
void reset();
void bindUTF8StringParameter(in unsigned long aParamIndex, in AUTF8String aValue);
void bindStringParameter(in unsigned long aParamIndex, in AString aValue);
void bindDoubleParameter(in unsigned long aParamIndex, in double aValue);
void bindInt32Parameter(in unsigned long aParamIndex, in long aValue);
void bindInt64Parameter(in unsigned long aParamIndex, in long long aValue);
void bindNullParameter(in unsigned long aParamIndex);
void bindBlobParameter(in unsigned long aParamIndex, [array,const,size_is(aValueSize)] in octet aValue, in unsigned long aValueSize);
void execute();
boolean executeStep();
The reset() method must be called on the statement after the last call of executeStep.
AString escapeStringForLIKE(in AString aValue, in wchar aEscapeChar);
An AString of an escaped version of aValue (%, _ and the escape char are escaped with the escape char).
For example, we will convert "foo/bar_baz%20cheese" into "foo//bar/_baz/%20cheese" (if the escape char is '/').
属性
parameterCount unsigned long Number of parameters.
columnCount unsigned long Number of columns returned.
state long The current state.
常量
Constant Value Description
MOZ_STORAGE_STATEMENT_INVALID 0 The SQL statement is Invalid.
MOZ_STORAGE_STATEMENT_READY 1 The SQL statement is ready to be executed.
MOZ_STORAGE_STATEMENT_EXECUTING 2 The SQL statement is executing at the moment.
3.
mozIStorageValueArray
函数
long getTypeOfIndex(in unsigned long aIndex);
long getInt32(in unsigned long aIndex);
long long getInt64(in unsigned long aIndex);
double getDouble(in unsigned long aIndex);
AUTF8String getUTF8String(in unsigned long aIndex);
AString getString(in unsigned long aIndex);
void getBlob(in unsigned long aIndex, out unsigned long aDataSize, [array,size_is(aDataSize)] out octet aData);
boolean getIsNull(in unsigned long aIndex);
属性
numEntries unsigned long The number of entries in the array (each corresponding to a column in the database row).
常量
Constant Value Description
VALUE_TYPE_NULL 0 Null data type.
VALUE_TYPE_INTEGER 1 INTEGER data type.
VALUE_TYPE_FLOAT 2 FLOAT data type.
VALUE_TYPE_TEXT 3 TEXT data type.
VALUE_TYPE_BLOB 4 BLOB data type.
4.
mozIStorageService
函数
nsIFile backupDatabaseFile(in nsIFile aDBFile, in AString aBackupFileName, [optional] in nsIFile aBackupParentDirectory);
mozIStorageConnection openDatabase(in nsIFile aDatabaseFile);
mozIStorageConnection openSpecialDatabase(in string aStorageKey);
mozIStorageConnection openUnsharedDatabase(in nsIFile aDatabaseFile);
发表评论
-
gz后仅5.5K的Rich Editor
2009-12-24 14:31 2035http://kissy.googlecode.com/sv ... -
windows监控目录改动
2009-07-30 16:30 3303先安装 http://sourceforge.net/proj ... -
每天写一点web框架 5
2009-07-29 23:31 1544继续 http://blog.html.it/layoutg ... -
每天写一点web框架 4
2009-07-28 10:02 1322昨天有事出差,先补上一篇 先 easy_install we ... -
每天写一点web框架 3
2009-07-26 11:22 1301http://code.google.com/p/zpyweb ... -
每天写一点web框架 2
2009-07-25 21:37 1242今天把url route弄好了 http://code.goo ... -
每天写一点web框架 1
2009-07-24 17:32 1446打算开始写一个web框架了 有空就写一点吧 今天写的是模 ... -
linux 命令 zcat , pgrep
2009-07-15 01:43 4806http://www.ibm.com/developerwor ... -
Tokyo Dystopia 全文搜索
2009-07-13 10:33 2242http://d.hatena.ne.jp/perezvon/ ... -
随笔...
2009-05-21 01:00 12331. 交换机的东西我一点不懂 今晚学了一点. 100M 电 ... -
jquery.wysiwyg.js
2009-05-19 01:58 7311http://code.google.com/p/jwysiw ... -
linux下安装dns本地缓存
2009-04-12 12:04 4295linux的版本是gentoo 写爬虫不用dns缓存很容易就 ... -
事前审查系统设计思路整理
2009-03-18 18:17 1491整理一下思路 先定义一个函数 function 发表函数( ... -
顺手写的一个tab样式
2009-03-02 16:39 2219<!DOCTYPE HTML PUBLIC &quo ... -
备忘:MySQL InnoDB Error "the table is full"
2009-02-23 13:16 3610http://blog.imminentweb.com/te ... -
LucidDB 备忘
2009-02-21 00:04 3342http://en.wikipedia.org/wiki ... -
js高亮关键词代码备忘
2009-02-17 11:42 2543当然是抄的啊:) 管理后台用这个很方便 <!DOCTY ... -
google reader 的 prompt 函数
2009-01-27 11:40 1671IE7对prompt做了限制,MS的产品部门真是好奇怪... ... -
jquery 1.3 event模型(消息<->订阅者)
2009-01-21 17:18 13291.3中对event进行改版,现在$(xxx).click等等 ... -
js抄袭笔记 -- 飞出
2009-01-20 15:39 1350这个博客http://james.padolsey.com ...
相关推荐
博文链接:https://zsp.iteye.com/blog/232047
《初识XUL用户界面UI开发》XUL是Mozilia社区开发技术中的一员,总要是为用户界面UI服务,Firefox就XUL以及其它一系列相关的基础库开发出来的成功之作。事实证明XUL是成功的UI开发技术,本文以一个最简明的视角来向看...
XUL开发手册.pdf
事实上,即将发布的 Firefox 4.0 不仅仅是由 XUL 构建的,但它提供了一个 XUL 运行时环境,允许任何 Firefox 用户运行其他 XUL 应用程序。在本教程,您开始使用 XUL 进行编程,并学习一些帮助您开发 XUL 应用程序的...
mozilla_firefox_xul_spoof
清晰给出繁杂配置和步骤, c++开发xpcom组件的完整例子, vs2005 环境配置 ,xpconnect调用xpcom组件, xul 中使用javascript 内有源码,配置图示
java运行依赖jar包
java运行依赖jar包
java运行依赖jar包
Firefox-52-ESR-legacy-addon:[WIP]在基于XUL的清除中断之前,Mozilla Firefox浏览器扩展,插件,addons.mozilla.org中的主题的精选列表和XPI文件
是一个xul music player
自己写的一个xul的小程序。...下载后,直接在firefox上安装,会在状态栏出现helloworld标签。 也是自己编辑本示例,将文件后缀改为zip,解压就可以看到示例的源代码。本示例支持最高firefoex3.6.8。
本文档详细介绍了Firefox扩展开发的详细过程,包括文档的组织结构,安装的配置以及一些基本的xul语法知识等,文档中的示例可以直接编辑,生成Firefox扩展。
企业信息网格中XUL-SQL技术的研究.pdf
分布式信息集成中XUL-SQL问题的研究.pdf
#Zimbra邮件通知程序(Firefox插件)描述Zimbra Mail Notifier检查您的Zimbra ...用法 # Maven is used to generate Firefox extension (xpi) of Zimbra Mail Notifier sources.# There are 2 profiles (Dev en Pro
xul是XML User Interface language 的简写,是Mozilla基金会开发的一种基于XML的标记语言,一般用来构造程序的界面,典型的firefox就是这种的实践,目前XUL只能被Firefox的浏览器支持,它和js,css,html等理论上能够...
XUL (XML User-interface Language - 基于 XML 的用户接口语言)是一种新的富客户端(Rich Client)技术,是 Mozilla 和 Firefox 的核心语言,是一种用来快速开发跨平台用户接口的新途径。其实不难发现很多新出现的...
解压 Firefox 插件文件并提取其 JavaScript 源代码。 用法 var XPI = require ( 'xpi' ) ; ( new XPI . SourceEmitter ( "./adblock_plus-2.6.7-sm+tb+fx+an.xpi" ) ) . on ( "script" , function ( script ) { ...
由于无法从Maven repository中下载依赖,因此提供kettle相关的jar包需要手动安装到maven仓库中,并提供了pom.xml作为参考