|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
Cluster/NDB高冗余的存储引擎,用多台数据机器联合提供服务以提高整体性能和安全性。适合数据量大,安全和性能要求高的应用静态|数据次要思绪办理了,上面入手下手写具体计划(以SybaseASE数据库为例,其他列位扩大):
1.创建两头层表vdt_columns,这个表的属性用于构建管道中的列材料.
实行相似的代码天生:
ls_sql="createtablevdt_columns("
ls_sql+="uidintnull,"
ls_sql+="upkeyvarchar(1)null,"
ls_sql+="udmidintnull,"
ls_sql+="udmnamevarchar(30)null,"
ls_sql+="unullsvarchar(1)null,"
ls_sql+="uwidthintnull,"
ls_sql+="uscaleintnull,"
ls_sql+="unamevarchar(30)null,"
ls_sql+="udefaultvarchar(255)null,"
ls_sql+="ucheckvarchar(255)null,"
ls_sql+="uidentityintnull"
ls_sql+=")"
EXECUTEIMMEDIATE:ls_sqlusingSrcSqlca;
2.构建其他相干的大概用到两头层视图:
体系工具视图:
ls_sql=createviewvdt_objects(uid,uuid,uname,utype)as+&
selectid,uid,name,(casetypewhen~TR~then~T~elsetypeend)fromsysobjects
EXECUTEIMMEDIATE:ls_sqlusingSrcSqlca;
体系表视图:
ls_sql=createviewvdt_tables(uid,uuid,uname)as+&
selectid,uid,namefromsysobjectswheretype=~U~
EXECUTEIMMEDIATE:ls_sqlusingSrcSqlca;
3.初始化vdt_columns表.
insertvdt_columns
selectsc.id,so.name,sc.colid,N,sc.type,
(casewhen(selectcount(*)fromsystypesstwheresc.type=st.typeandsc.usertype=st.usertype)=0then(selectmax(st.name)fromsystypesstwheresc.type=st.type)else(selectst.namefromsystypesstwheresc.type=st.typeandsc.usertype=st.usertype)end),
N,(casewhenprecisnotnullthenisnull(sc.prec,0)elsesc.lengthend),
sc.scale,sc.name,substring(sy.text,9,char_length(sy.text)-8),"0",(casewhensc.status=128then1else0end)
fromsyscolumnssc,sysobjectsso,syscommentssy
wheresc.id*=so.idandsc.cdefault*=sy.id
usingSrcSqlca;
在Sybase中,断定主键列对照贫苦:
declarecur_vdtcolumnscursorfor
selectdistinctutnamefromvdt_columns
usingSrcSqlca;
opencur_vdtcolumns;
fetchcur_vdtcolumnsinto:ls_utname;
dowhileSrcSqlca.sqlcode=0
wait(true)
ls_nulls=;ls_pkey=
of_getnull_ase(ls_utname,ls_nulls)
of_getpk_ase(ls_utname,ls_pkey)
iflen(ls_pkey)>0then
updatevdt_columns
setupkey=Y,unulls=N
whereCHARINDEX(uname,:ls_pkey)>0
andutname=:ls_utname
usingSrcSqlca;
endif
fetchcur_vdtcolumnsinto:ls_utname;
loop
endif
个中of_getpk_ase()用于断定某列是不是是主键.
/*Outofdate*/
LongLl_Cnt
intLi_keycnt,Li_indexid,Li_indstat,Li_indstat2
StringLs_keys,Ls_ThisKey
intLi_i
IfNotIsValid(SrcSqlca)Thenreturn-1
SelectCount(*)Into:Ll_CntFromsysobjectsWherename=:as_tablenameUsingSrcSqlca;
IfLl_Cnt<=0Then
return-2
Endif
DECLAREcurs_sysindexesCURSORFOR
SELECTkeycnt,indid,status,status2
FROMsysindexes
WHEREid=object_id(:as_tablename)ANDindid>0UsingSrcSqlca;
OPENcurs_sysindexes;
FETCHcurs_sysindexesINTO:Li_keycnt,:Li_indexid,:Li_indstat,:Li_indstat2;
dowhile(SrcSqlca.Sqlcode=0)
IfMod(int(Li_indstat2/2),2)=1Then
IFMod(int(Li_indstat/2048),2)=1Then//主键
Ls_Keys=
Li_i=1
dowhileLi_i<=Li_keycnt
Selectdistinctindex_col(:as_tablename,:Li_indexid,:Li_i)into:Ls_ThisKey
Fromvdt_columnsUsingSrcSqlca;
IfIsnull(Ls_ThisKey)Then
Exit
Else
IfLi_i>1ThenLs_keys+=,
Ls_Keys+=Ls_ThisKey
Endif
Li_i++
loop
Endif
Endif
FETCHcurs_sysindexesINTO:Li_keycnt,:Li_indexid,:Li_indstat,:Li_indstat2;
loop
CLOSEcurs_sysindexes;
as_keys=Ls_keys
return1
经由以上的步骤,两头层的数据就基础取得了,依据这些数据,基础上可以无偏差的传输尽年夜部分表.构建了两头层,为今后的分歧数据库的扩大打下了一个优秀的基本.
分歧的数据库,机关两头层的语法各有分歧,可是两头层的表(视图)的布局是一样的,如许程序中处置的办法也一致了.
待续...
支持多种存储引擎。 |
|