正则表达式 mysql字段转oracle一例

某mysql字段如下:
`test_id` int(11) not null auto_increment comment '自增字段',
而且有大量的这样字段需要转到oracle,首先我们知道oracle的字段描述里面是没有comment的,但是同时也需要保留comment信息。使用正则表达式来转换,用notepad++正则表达式替换:
查找目标:

comment(.*),

替换为:

,comment\1

\1表示的是(.*)的内容
最后替换为:
`staff_id` int(11) not null auto_increment ,– '自增字段'
然后去掉反引号,去掉auto_increment,手动加上constraint primary key。

Tagged , , | Leave a comment

sql语句格式化工具 SQL formatting tool

  • SQL Review – SQL formatting tool
    1. 一个java写的gui程序(运行需要安装jre),支持java,perl,php,c#,vb(asp)的语法输出。
    2. 支持设定关键字和语句的大小写
    3. 支持设定“字段分割符”逗号设定在头部还是尾部
    4. 支持设定压缩空格
    5. 设定行号
    6. 自定义包裹字段名的符号(默认是反引号)
    7. 自定义缩进
  • SQL Formatter
    1. 在线java applet,无需安装,免费,非开源。
    2. 和SQL Review一样,支持各种语言输出
    3. 原SQL支持:DB2/UDB/Oracle/Access/SQL Server/MySQL/Sybase/PostgreSQL/Informix
    4. 自定义缩进
    5. 各种复杂的换行配置
    6. 各种语句的空格、逗号设置
  • SQLFormat – Online SQL Formatting Service
    1. appspot站点,需要翻墙,有源码、API
    2. 去掉注释
    3. 语法高亮
    4. 支持文件上传
    5. 支持各种语言输出
  • T-SQL Tidy
    1. 各种各样的复杂设置
  • SQL and PL/SQL Formatter
  • http://www.ascdesc.com/ 关键字大写转化
  •  
Leave a comment

oracle给not null约束指定名称

一般我们建表结构的时候都是使用以下的形式:

create table test(
menuid number(8) default '0' not null,
name varchar2(40) not null,
id_parent number(10) not null,
url varchar2(300) null,
constraint pk_test primary key(menuid)
);


执行后,查看这个test表的所有约束:

select constraint_name,table_name from user_constraints

发现命名都是SYS_CXXXXXX(XXXXXX表示数字),这些是oracle自动给约束的命名,我感觉为了提高以后数据库的可维护性,还是需要给not null约束指定名称,语法很简单:

create table test(
menuid number(8) default '0' constraint menuid_nn not null,
name varchar2(40) constraint name_nn not null,
id_parent number(10) constraint id_parent_nn not null,
url varchar2(300) null,
constraint pk_test primary key(menuid)
)


参考

Tagged | Leave a comment

oracle没有create or replace table

SQL> create or replace table testTb;
create or replace table testTb
ORA-00922: 选项缺失或无效
只能使用先drop再create来代替
drop table testTb;
create teble testTb(
    fid   varchar2(4),
    fname   varchar2(10)
);
可以用create or replace的对象有:functions, procedures, packages, types, synonyms, trigger and views,就是没有table,也没有sequence。 drop掉一个并不存在的表报错:
SQL> drop table non_exists;
drop table non_exists
ORA-00942: 表或视图不存在
drop table容错的方法是:
BEGIN
  DROP TABLE non_exists_table;
EXCEPTION
  WHEN OTHERS THEN
    IF sqlcode != -0942 THEN RAISE; END IF;
END;
/
错误代码:-0942
drop sequence容错的方法是:
BEGIN
  DROP SEQUENCE non_exists_sequence;
EXCEPTION
  WHEN OTHERS THEN
    IF sqlcode != -2289 THEN RAISE; END IF;
END;
/
错误代码:-2289 参考
Tagged | Leave a comment

支持firefox 4的autoproxy扩展

版本 0.4b1.0+.2011032419 March 24, 2011 114.7 KB

0.4b2.2011041023 发布了。

所有版本:https://addons.mozilla.org/zh-CN/firefox/addon/autoproxy/versions/

支持 Firefox 4 :-) ,还没有通过firefox addon审核。
Tagged | Leave a comment

#167 codeigniter oci8 database driver do not support setting charset and session_mode while ocilogon() to oracle db

system/database/drivers/oci8/oci8_driver.php line 80 db_connect() function did not support set the charset and session mode while connecting to oracle db.
function db_connect()
    {
        return @ocilogon($this->username, $this->password, $this->hostname);
    }
function db_pconnect()
    {
        return @ocilogon($this->username, $this->password, $this->hostname);
    }
here is the prototype of oci_connect( ocilogon improved version )
resource oci_connect ( string $username , string $password [, string $db [, string $charset [, int $session_mode ]]] )
codeigniter最新的2.0.1太蛋疼鸟。system/database/drivers/oci8/oci8_driver.php里面的db_connect()和db_pconnect()函数尽然不支持连接的时候设定字符集,因为函数的原形ocilogon(被oci_connect代替)支持设定charset和session_mode。还有codeigniter为啥要使用@ocilogon而非oci_connect呢?php官方说5.0.0以前的版本才使用ocilogon,codeigniter为了使用ocilogon不报warning还前面加上了”@”符号。但是codeigniter声称是支持php 5.1.6以及以后版本的php框架。有点搞不懂codeigniter的想法了。 没有版本,这个问题,只有通过hard coding修改oci8_driver.php文件的db_connect()和db_pconnect()函数为:
	function db_connect()
	{
		return @ociplogon($this->username, $this->password, $this->hostname, $this->char_set);
	}
	function db_pconnect()
	{
		return @ociplogon($this->username, $this->password, $this->hostname, $this->char_set);
	}
已经将这个问题提交到bitbucket
Tagged , , , | Leave a comment

codeigniter配置oracle数据库连接

Connection Parameters

Not all of the parameters in application/config/database.php are used as one might expect.  Namely, $db[‘default’][‘database’] isn’t used at all.  The value used for $db[‘default’][‘hostname’] depends on whether the Oracle client’s tnsnames.ora file exists and contains information about the database to be used.  If the file exists and is configured for the intended database, this parameter should be set to the symbolic name.  Otherwise, it should be set to a single string of the connection parameters that tnsmames.ora would normally contain.

An example of connection parameters for the latter case:

$db['default']['hostname'] = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=orcl)))';
$db['default']['username'] = 'dbuser';
$db['default']['password'] = 'dbpassword';
$db['default']['database'] = ''; // not used by this Oracle driver
$db['default']['dbdriver'] = 'oci8';

In this case, the appropriate values need to be set for the HOST, PORT, and SID keywords in the hostname parameter.

via

Tagged , , | Leave a comment

codeigniter字符集编码问题

codeigniter里面的php文件都是ansi编码,其实我们在添加controller,model,view等php文件的时候,php文件的编码成了一个问题。其实这个关系不大。 如果真个项目采用utf-8,那么就将php文件的编码设置为utf-8 without bom,然后html模板文件meta写成:
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
mysql数据库统一字符集utf-8,校队:utf8_general_ci 就可以了,系统可以在“标准规范模式”正常浏览不出现乱码。 可能在后期处理上传的ms office文档的时候有转码的需要。
Tagged | 1 Comment

4次重装oracle的教训(OracleDBConsoleORCL启动错误:系统错误3)

  • 安装前请确定机子的ip不是dhcp获取的,否则当重新获得了ip,就无法连接,就杯具了。
  • 最好是拔点网线,然后停用vmware的所有虚拟网站和无线网卡
  • D:\oracle\product\10.2.0\db_1 目录下有个x.x.x.x_orcl目录,那个x.x.x.x就是你安装时候oracle获取你的主机ip,如果获取的是dhcp ip就杯具了。如果是主机名_orcl或者是localhost_orcl就ok。不过我估计即便是被dhcp悲剧了也能手动修改回来的,我也尝试了,但是失败,应该还有我没有触及到的神秘文件。
Tagged | Leave a comment

CodeIgniter用Xdebug调试的问题:The URI you submitted has disallowed characters.

最近玩codeigniter,使用netbeans写代码,调试器使用xdebug(貌似netbeans不支持zend debugger?之前用过的zend studio支持zend debugger),写了一个demo,然后ctrl+F5调试的时候,进过(F8)了几步之后出现如图上的问题:”The URI you submitted has disallowed characters.”,因为codeigniter对$_GET、$_POST等外来参数有一个“白名单”的机制来加强了安全性,如果你的参数没有加入“白名单”,那肯定是有问题了。 而xdebug调试的时候自动加上了参数 XDEBUG_SESSION_START,所以肯定报错。
http://ci-study/index.php?XDEBUG_SESSION_START=tun-xdebug

An Error Was Encountered

The URI you submitted has disallowed characters.
在CI 2.0的/application/config/config.php Line 112有以下内容:
/*
|--------------------------------------------------------------------------
| Allowed URL Characters
|--------------------------------------------------------------------------
|
| This lets you specify with a regular expression which characters are permitted
| within your URLs.  When someone tries to submit a URL with disallowed
| characters they will get a warning message.
|
| As a security measure you are STRONGLY encouraged to restrict URLs to
| as few characters as possible.  By default only these are allowed: a-z 0-9~%.:_-
|
| Leave blank to allow all characters -- but only if you are insane.
|
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
*/
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
CI采用了正则表达式的方式来匹配白名单,尽量少的匹配字符串意味着更高的安全性,默认是a-z 0-9~%.:_\-

解决方法1:

放弃netbeans,使用eclipse+PDT,zend studio等可以使用zend debugger的PHP IDE。(为了一个小问题换IDE有点蛋疼的说)

解决方法2:

将:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
修改为:
$config['permitted_uri_chars'] = 'a-z A-Z 0-9~%.:_\-';
实际部署中,最好还原到默认的permitted_uri_chars,提高安全性。
Tagged , , | Leave a comment