uo_yfimex_pipeline.sru 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. $PBExportHeader$uo_yfimex_pipeline.sru
  2. forward
  3. global type uo_yfimex_pipeline from nonvisualobject
  4. end type
  5. end forward
  6. global type uo_yfimex_pipeline from nonvisualobject
  7. end type
  8. global uo_yfimex_pipeline uo_yfimex_pipeline
  9. type variables
  10. datastore ds_columns,ds_tables
  11. nvo_pipeline invo_pipeline // pipeline用户对象
  12. end variables
  13. forward prototypes
  14. private function string p_tran_error_mess (integer mess_id)
  15. private function boolean p_change_db_type (string as_src_dbms, string as_dst_dbms, ref string as_src_type, ref string as_src_dbtype, ref string as_dst_type, ref string as_dst_dbtype, integer ai_prec, integer ai_scale, string as_isnull, ref string as_init, integer ai_length)
  16. public function integer pf_writetifofile (string arg_tableinfo, string arg_objfilename, ref string arg_msg)
  17. private function integer p_create_pipesyntax (transaction itr_source, transaction itr_target, integer commitstep, integer maxerrors, long ai_table_id, string as_table_name, string as_table_filterstring, ref string arg_pipe_syntax, ref string arg_msg, integer arg_createtype)
  18. public function integer uf_pl_execute (transaction itr_source, transaction itr_target, datawindow dw_error, s_exporttableinfo arg_zipfileinfo[], integer arg_tableno, integer arg_commitstep, integer arg_maxerrors, ref string arg_msg, ref string arg_log, boolean arg_if_buildlogfile)
  19. end prototypes
  20. private function string p_tran_error_mess (integer mess_id);//转换传递错误信息
  21. //p_tran_error_mess(mess_id)
  22. String Return_mess
  23. Return_mess = ''
  24. Choose case Mess_ID
  25. case -1
  26. Return_mess = '管道打开错误'
  27. Return Return_mess + '('+string(Mess_id)+')'
  28. case -2
  29. return_mess = '太多的列'
  30. Return Return_mess + '('+string(Mess_id)+')'
  31. case -3
  32. Return_mess = '表已经存在'
  33. Return Return_mess + '('+string(Mess_id)+')'
  34. case -4
  35. return_mess = '不存在制定的表'
  36. Return Return_mess + '('+string(Mess_id)+')'
  37. case -5
  38. return_mess = '连接丢失'
  39. Return Return_mess + '('+string(Mess_id)+')'
  40. case -6
  41. return_mess = '无效的参数'
  42. Return Return_mess + '('+string(Mess_id)+')'
  43. case -7
  44. return_mess = '列格式不匹配'
  45. Return Return_mess + '('+string(Mess_id)+')'
  46. case -8
  47. return_mess = '源SQL语法致命错误'
  48. Return Return_mess + '('+string(Mess_id)+')'
  49. case -9
  50. return_mess = '目的SQL语法致命错误'
  51. Return Return_mess + '('+string(Mess_id)+')'
  52. case -10
  53. return_mess = '已经到达最大错误数'
  54. Return Return_mess + '('+string(Mess_id)+')'
  55. case -12
  56. return_mess = '错误的表语法'
  57. Return Return_mess + '('+string(Mess_id)+')'
  58. case -13
  59. return_mess = '没有提供需要的键名'
  60. Return Return_mess + '('+string(Mess_id)+')'
  61. case -15
  62. return_mess = '管道已经在执行'
  63. Return Return_mess + '('+string(Mess_id)+')'
  64. case -16
  65. return_mess = '源数据库错误'
  66. Return Return_mess + '('+string(Mess_id)+')'
  67. case -17
  68. return_mess = '目的数据库错误'
  69. Return Return_mess + '('+string(Mess_id)+')'
  70. case -18
  71. return_mess = '目的数据库为只读'
  72. Return Return_mess + '('+string(Mess_id)+')'
  73. case else
  74. return 'OK'
  75. end choose
  76. end function
  77. private function boolean p_change_db_type (string as_src_dbms, string as_dst_dbms, ref string as_src_type, ref string as_src_dbtype, ref string as_dst_type, ref string as_dst_dbtype, integer ai_prec, integer ai_scale, string as_isnull, ref string as_init, integer ai_length);//不同数据库数据类型转换
  78. string ls_src_type
  79. as_init = ''
  80. ls_src_type = as_src_type
  81. ////例 MSS - ORA//
  82. if left(as_src_dbms,3) = 'MSS' and left(as_dst_dbms,3) = 'O84' then
  83. choose case ls_src_type
  84. case 'char','nchar'
  85. as_src_type = 'char'
  86. as_dst_type = 'char'
  87. as_src_dbtype = 'char('+string(ai_prec)+')'
  88. as_dst_dbtype = 'CHAR('+string(ai_prec)+')'
  89. if as_isnull = 'no' then as_init = ',initial_value="spaces"'
  90. case 'varchar','nvarchar'
  91. as_src_type = 'varchar'
  92. as_dst_type = 'varchar'
  93. as_src_dbtype = 'varchar('+string(ai_prec)+')'
  94. as_dst_dbtype = 'VARCHAR2('+string(ai_prec)+')'
  95. if as_isnull = 'no' then as_init = ',initial_value="spaces"'
  96. case 'int'
  97. as_src_type = 'long'
  98. as_src_dbtype = 'int'
  99. as_dst_type = 'double'
  100. as_dst_dbtype = 'NUMBER('+string(ai_prec)+',0)'
  101. if as_isnull = 'no' then as_init = ',initial_value="0"'
  102. case 'smallint'
  103. as_src_type = 'int'
  104. as_src_dbtype = 'smallint'
  105. as_dst_type = 'double'
  106. as_dst_dbtype = 'FLOAT'
  107. if as_isnull = 'no' then as_init = ',initial_value="0"'
  108. case 'tinyint'
  109. as_src_type = 'int'
  110. as_src_dbtype = 'tinyint'
  111. as_dst_type = 'decimal'
  112. as_dst_dbtype = 'NUMBER(3,0)'
  113. if as_isnull = 'no' then as_init = ',initial_value="0"'
  114. case 'float'
  115. as_src_type = 'double'
  116. as_src_dbtype = 'float'
  117. as_dst_type = 'double'
  118. as_dst_dbtype = 'FLOAT'
  119. if as_isnull = 'no' then as_init = ',initial_value="0"'
  120. case 'real'
  121. as_src_type = 'real'
  122. as_src_dbtype = 'real'
  123. as_dst_type = 'double'
  124. as_dst_dbtype = 'FLOAT'
  125. if as_isnull = 'no' then as_init = ',initial_value="0"'
  126. case 'text'
  127. as_src_type = 'string'
  128. as_src_dbtype = 'text'
  129. as_dst_type = 'string'
  130. as_dst_dbtype = 'LONG VARCHAR'
  131. if as_isnull = 'no' then as_init = ',initial_value="spaces"'
  132. case 'bit'
  133. as_src_type = 'bit'
  134. as_src_dbtype = 'bit'
  135. as_dst_type = 'double'
  136. as_dst_dbtype = 'FLOAT'
  137. if as_isnull = 'no' then as_init = ',initial_value="0"'
  138. case 'decimal','numeric'
  139. as_src_type = 'decimal'
  140. as_src_dbtype = 'decimal('+string(ai_prec)+','+string(ai_scale)+')'
  141. as_dst_type = 'decimal'
  142. as_dst_dbtype = 'NUMBER('+string(ai_prec)+','+string(ai_scale)+')'
  143. if as_isnull = 'no' then as_init = ',initial_value="0"'
  144. case 'money'
  145. as_src_type = 'money'
  146. as_src_dbtype = 'money'
  147. as_dst_type = 'decimal'
  148. as_dst_dbtype = 'NUMBER(19,4)'
  149. if as_isnull = 'no' then as_init = ',initial_value="0"'
  150. case 'smallmoney'
  151. as_src_type = 'smallmoney'
  152. as_src_dbtype = 'smallmoney'
  153. as_dst_type = 'decimal'
  154. as_dst_dbtype = 'NUMBER(10,4)'
  155. if as_isnull = 'no' then as_init = ',initial_value="0"'
  156. case 'datetime'
  157. as_src_type = 'datetime'
  158. as_src_dbtype = 'datetime'
  159. as_dst_type = 'datetime'
  160. as_dst_dbtype = 'DATE'
  161. if as_isnull = 'no' then as_init = ',initial_value="today()"'
  162. case 'smalldatetime'
  163. as_src_type = 'datetime'
  164. as_src_dbtype = 'smalldatetime'
  165. as_dst_type = 'datetime'
  166. as_dst_dbtype = 'DATE'
  167. case 'binary' // ,'image'
  168. as_src_type = 'blob'
  169. as_src_dbtype = 'binary(11)'
  170. as_dst_type = 'blob'
  171. as_dst_dbtype = 'RAW(11)'
  172. if as_isnull = 'no' then as_init = ',initial_value="spaces"'
  173. case else
  174. return false
  175. end choose
  176. return true
  177. end if
  178. //例 MSS - MSS//
  179. if left(as_src_dbms,3) = 'MSS' and left(as_dst_dbms,3) = 'MSS' then
  180. choose case ls_src_type
  181. case 'char','nchar'
  182. as_src_type = 'char'
  183. as_dst_type = 'char'
  184. as_src_dbtype = 'char'
  185. as_dst_dbtype = 'char'
  186. if as_isnull = 'no' then as_init = ',initial_value="spaces"'
  187. case 'varchar','nvarchar'
  188. as_src_type = 'varchar'
  189. as_dst_type = 'varchar'
  190. as_src_dbtype = 'varchar'
  191. as_dst_dbtype = 'varchar'
  192. if as_isnull = 'no' then as_init = ',initial_value="spaces"'
  193. case 'int'
  194. as_src_type = 'long'
  195. as_src_dbtype = 'int'
  196. as_dst_type = 'long'
  197. as_dst_dbtype = 'int'
  198. if as_isnull = 'no' then as_init = ',initial_value="0"'
  199. case 'smallint'
  200. as_src_type = 'int'
  201. as_src_dbtype = 'smallint'
  202. as_dst_type = 'int'
  203. as_dst_dbtype = 'smallint'
  204. if as_isnull = 'no' then as_init = ',initial_value="0"'
  205. case 'tinyint'
  206. as_src_type = 'int'
  207. as_src_dbtype = 'tinyint'
  208. as_dst_type = 'int'
  209. as_dst_dbtype = 'tinyint'
  210. if as_isnull = 'no' then as_init = ',initial_value="0"'
  211. case 'float'
  212. as_src_type = 'double'
  213. as_src_dbtype = 'float'
  214. as_dst_type = 'double'
  215. as_dst_dbtype = 'float'
  216. if as_isnull = 'no' then as_init = ',initial_value="0"'
  217. case 'real'
  218. as_src_type = 'real'
  219. as_src_dbtype = 'real'
  220. as_dst_type = 'real'
  221. as_dst_dbtype = 'real'
  222. if as_isnull = 'no' then as_init = ',initial_value="0"'
  223. case 'text'
  224. as_src_type = 'string'
  225. as_src_dbtype = 'text'
  226. as_dst_type = 'string'
  227. as_dst_dbtype = 'text'
  228. if as_isnull = 'no' then as_init = ',initial_value="spaces"'
  229. case 'bit'
  230. as_src_type = 'bit'
  231. as_src_dbtype = 'bit'
  232. as_dst_type = 'bit'
  233. as_dst_dbtype = 'bit'
  234. if as_isnull = 'no' then as_init = ',initial_value="0"'
  235. case 'decimal','numeric'
  236. as_src_type = 'decimal'
  237. as_src_dbtype = 'numeric'
  238. as_dst_type = 'decimal'
  239. as_dst_dbtype = 'NUMBER('+string(ai_prec)+','+string(ai_scale)+')'
  240. if as_isnull = 'no' then as_init = ',initial_value="0"'
  241. case 'money'
  242. as_src_type = 'money'
  243. as_src_dbtype = 'money'
  244. as_dst_type = 'money'
  245. as_dst_dbtype = 'money'
  246. if as_isnull = 'no' then as_init = ',initial_value="0"'
  247. case 'smallmoney'
  248. as_src_type = 'smallmoney'
  249. as_src_dbtype = 'smallmoney'
  250. as_dst_type = 'smallmoney'
  251. as_dst_dbtype = 'smallmoney'
  252. if as_isnull = 'no' then as_init = ',initial_value="0"'
  253. case 'datetime'
  254. as_src_type = 'datetime'
  255. as_src_dbtype = 'datetime'
  256. as_dst_type = 'datetime'
  257. as_dst_dbtype = 'datetime'
  258. if as_isnull = 'no' then as_init = ',initial_value="today"'
  259. case 'smalldatetime'
  260. as_src_type = 'datetime'
  261. as_src_dbtype = 'smalldatetime'
  262. as_dst_type = 'datetime'
  263. as_dst_dbtype = 'smalldatetime'
  264. case 'binary' // ,'image'
  265. as_src_type = 'blob'
  266. as_src_dbtype = 'binary(11)'
  267. as_dst_type = 'blob'
  268. as_dst_dbtype = 'binary(11)'
  269. if as_isnull = 'no' then as_init = ',initial_value="spaces"'
  270. case else
  271. return false
  272. end choose
  273. return true
  274. end if
  275. /////////////
  276. return false
  277. end function
  278. public function integer pf_writetifofile (string arg_tableinfo, string arg_objfilename, ref string arg_msg);//pf_writetifofile(arg_tableinfo,arg_objfilename,arg_msg)
  279. integer li_FileNum,rslt=1,ls_jh
  280. li_FileNum = FileOpen( arg_objfilename,StreamMode!, Write!, LockWrite!, Replace!)
  281. if li_FileNum<=0 then
  282. arg_msg="打开文件"+arg_objfilename+"失败"
  283. rslt=0
  284. fileclose(li_FileNum)
  285. goto ext
  286. end if
  287. ls_jh=FileWrite(li_FileNum, arg_tableinfo)
  288. if ls_jh<=0 then
  289. arg_msg="写文件"+arg_objfilename+"失败"
  290. rslt=0
  291. fileclose(li_FileNum)
  292. goto ext
  293. end if
  294. fileclose(li_FileNum)
  295. ext:
  296. return rslt
  297. end function
  298. private function integer p_create_pipesyntax (transaction itr_source, transaction itr_target, integer commitstep, integer maxerrors, long ai_table_id, string as_table_name, string as_table_filterstring, ref string arg_pipe_syntax, ref string arg_msg, integer arg_createtype);//建立pipe line 语法
  299. //p_create_pipesyntax(itr_source,itr_target,commitstep,maxerrors,ai_table_id,as_table_name,arg_pipe_syntax,arg_msg,arg_createtype)
  300. //arg_createtype=1 :直接建SQL语句
  301. int rslt=1
  302. long ll_rowcount
  303. ds_columns.setfilter('syscolumns_id='+string(ai_table_id))
  304. ds_columns.filter()
  305. ds_columns.setsort('syscolumns_colorder A')
  306. ds_columns.sort()
  307. ll_rowcount = ds_columns.rowcount()
  308. if ll_rowcount = 0 then
  309. arg_msg='表 '+string(ai_table_id)+' '+as_table_name + ' 没有列。'
  310. rslt=0
  311. goto ext
  312. end if
  313. //查询primary key===========
  314. s_sys_tntblinfo ls_tntblinfo
  315. string ls_sc_id_name,ls_Indcolumn_name,ls_thr_Indcolumn_name,ls_fou_Indcolumn_name
  316. string ls_fif_Indcolumn_name,ls_six_Indcolumn_name,ls_sev_Indcolumn_name,ls_eig_Indcolumn_name
  317. if f_get_tntblinfo(as_table_name,ls_tntblinfo)=1 then
  318. ls_sc_id_name=trim(ls_tntblinfo.Sc_id_name)
  319. ls_Indcolumn_name=trim(ls_tntblinfo.Indcolumn_name)
  320. ls_thr_Indcolumn_name=trim(ls_tntblinfo.thrIndcolumn_name)
  321. ls_fou_Indcolumn_name=trim(ls_tntblinfo.fouIndcolumn_name)
  322. ls_fif_Indcolumn_name=trim(ls_tntblinfo.fifIndcolumn_name)
  323. ls_six_Indcolumn_name=trim(ls_tntblinfo.sixIndcolumn_name)
  324. ls_sev_Indcolumn_name=trim(ls_tntblinfo.sevIndcolumn_name)
  325. ls_eig_Indcolumn_name=trim(ls_tntblinfo.eigIndcolumn_name)
  326. else
  327. arg_msg=as_table_name+"不在系统记录中;"
  328. rslt=0
  329. goto ext
  330. end if
  331. //==========================
  332. string ls_key_column
  333. long ll_key_count,ll_row,ll_find_row
  334. string ls_name,ls_type,ls_isnull,ls_src_dbtype,ls_dst_dbtype,ls_iskey,ls_src_type,ls_dst_Type
  335. integer li_isnull
  336. string ls_syn_src,ls_syn_ret,ls_syn_dst,ls_syn_hea,ls_ret
  337. string ls_dst_init
  338. integer li_prec,li_scale,li_length
  339. ls_syn_hea = 'PIPELINE(source_connect='+itr_source.Database+',destination_connect='+itr_target.Database+',type=update,commit='+string(commitstep)+',errors='+string(maxerrors)+',keyname="'+as_table_name+'")'
  340. ls_syn_src = 'SOURCE(name="'+as_table_name+'",'
  341. if arg_createtype=1 then
  342. ls_syn_ret = 'RETRIEVE(statement=" '+ as_table_filterstring+'")'
  343. else
  344. ls_syn_ret = 'RETRIEVE(statement="SELECT * from '+as_table_name + as_table_filterstring+'")'
  345. end if
  346. ls_syn_dst = 'DESTINATION(name="'+as_table_name+'",'
  347. ls_Ret = char(13) + char(10)
  348. for ll_row = 1 to ll_rowcount
  349. ls_name = ds_columns.object.syscolumns_name[ll_Row]
  350. ls_type = ds_columns.object.systypes_name[ll_Row]
  351. li_prec = ds_columns.object.syscolumns_prec[ll_row]
  352. li_scale = ds_columns.object.syscolumns_scale[ll_row]
  353. li_isnull = ds_columns.object.syscolumns_isnullable[ll_Row]
  354. li_length = ds_columns.object.syscolumns_length[ll_Row]
  355. if li_isnull= 1 then ls_isnull = 'yes' else ls_isnull = 'no'
  356. if isnull(li_scale) then li_scale = 0
  357. //检查primary key===========
  358. boolean if_pkkey
  359. if_pkkey=false
  360. ls_iskey=''
  361. if lower(ls_name) = lower(ls_sc_id_name) and lower(ls_sc_id_name) <>'' then
  362. if_pkkey=true
  363. end if
  364. if lower(ls_name) = lower(ls_Indcolumn_name) and lower(ls_Indcolumn_name) <>'' then
  365. if_pkkey=true
  366. end if
  367. if lower(ls_name) = lower(ls_thr_Indcolumn_name) and lower(ls_thr_Indcolumn_name) <>'' then
  368. if_pkkey=true
  369. end if
  370. if lower(ls_name) = lower(ls_fou_Indcolumn_name) and lower(ls_fou_Indcolumn_name) <>'' then
  371. if_pkkey=true
  372. end if
  373. if lower(ls_name) = lower(ls_fif_Indcolumn_name) and lower(ls_fif_Indcolumn_name) <>'' then
  374. if_pkkey=true
  375. end if
  376. if lower(ls_name) = lower(ls_six_Indcolumn_name) and lower(ls_six_Indcolumn_name) <>'' then
  377. if_pkkey=true
  378. end if
  379. if lower(ls_name) = lower(ls_sev_Indcolumn_name) and lower(ls_sev_Indcolumn_name) <>'' then
  380. if_pkkey=true
  381. end if
  382. if lower(ls_name) = lower(ls_eig_Indcolumn_name) and lower(ls_eig_Indcolumn_name) <>'' then
  383. if_pkkey=true
  384. end if
  385. if if_pkkey then
  386. ls_iskey = 'key=yes,'
  387. else
  388. ls_iskey = ''
  389. end if
  390. //==========================
  391. ls_dst_init = ''
  392. ls_src_dbtype = space(100)
  393. ls_dst_dbtype = space(100)
  394. ls_dst_init = space(100)
  395. ls_dst_type = space(30)
  396. ls_src_type = ls_type
  397. //改变数据类型
  398. if NOT p_change_db_type(&
  399. itr_source.dbms,&
  400. itr_target.dbms,&
  401. ls_src_type,&
  402. ls_src_dbtype,&
  403. ls_dst_Type,&
  404. ls_dst_dbtype,&
  405. li_prec,&
  406. li_scale,&
  407. ls_isnull,&
  408. ls_dst_init,&
  409. li_length) then continue
  410. // source 数据定义
  411. ls_syn_src += 'COLUMN(type='+ls_src_type+',name="'+ls_name+'",dbtype="'+ls_src_dbtype+'",'+ls_iskey+'nulls_allowed='+lower(ls_isnull)+')'
  412. // destination 定义
  413. if ls_type = 'char' then ls_Type = 'varchar'
  414. ls_syn_dst += 'COLUMN(type='+ls_dst_type+',name="'+ls_name+'",dbtype="'+ls_dst_dbtype+'",'+ls_iskey+'nulls_allowed='+lower(ls_isnull)+ls_dst_init+')'
  415. // 好看而已。
  416. if ll_row < ll_rowcount then
  417. ls_syn_src += ls_ret + ' '
  418. ls_syn_dst += ls_ret + ' '
  419. else
  420. ls_syn_src += ')'
  421. ls_syn_dst += ')'
  422. end if
  423. end for
  424. arg_pipe_syntax = ls_syn_hea + ls_ret+ls_syn_src +ls_ret+ls_syn_ret +ls_Ret+ ls_syn_dst
  425. ext:
  426. return rslt
  427. end function
  428. public function integer uf_pl_execute (transaction itr_source, transaction itr_target, datawindow dw_error, s_exporttableinfo arg_zipfileinfo[], integer arg_tableno, integer arg_commitstep, integer arg_maxerrors, ref string arg_msg, ref string arg_log, boolean arg_if_buildlogfile);//执行管道传送数据
  429. //uf_pl_execute(itr_source,itr_target,dw_error,arg_zipfileinfo[],arg_tableno,arg_commitstep,arg_maxerrors,arg_msg,arg_log)
  430. //itr_source :源数据源
  431. //itr_target :目标数据源
  432. //dw_error :显示错误dw
  433. //arg_zipfileinfo[300] :要导出的表的名称列表
  434. //arg_tableno :表数目
  435. //arg_commitstep :提交步长
  436. //arg_maxerrors :允许最大错误数目
  437. //arg_log :返回信息
  438. //1.create dw,检查传送数据数目
  439. //2.建立管道传送数据
  440. int rslt=1
  441. long lg_rowcount,table_pipeline_fail
  442. long ls_i
  443. s_sys_tntblinfo ls_tntblinfo
  444. string ls_msg
  445. string char_enter
  446. string str_dwSQl,str_SyntaxFromSQL
  447. DataStore ds_data
  448. ulong ll_table_id //表单ID,长整形数
  449. string str_Syntax_PipeLine, ls_pipe_result //pipeline语法,pipe结果
  450. string ls_table_name //表单名称
  451. string ls_table_filterstring
  452. int ls_createtype
  453. long ll_table_row,ll_pipe_result
  454. long ls_rowsread,ls_rowswritten,ls_rowsInerror
  455. long ls_total_rowsread,ls_total_rowswritten,ls_total_rowsInerror
  456. ds_data=create DataStore
  457. invo_pipeline = create nvo_pipeline
  458. ds_tables =create DataStore //初始化table dw
  459. ds_columns=create DataStore //初始化column dw
  460. ds_tables.dataobject='d_tables_mss'
  461. ds_columns.dataobject='d_columns_mss'
  462. ds_tables.settransobject(itr_source)
  463. ds_columns.settransobject(itr_source)
  464. ds_tables.retrieve()
  465. ds_columns.retrieve()
  466. char_enter=char(13)+char(10) //换行符
  467. open(w_sys_wait_2jdt) //初始化进度条
  468. w_sys_wait_2jdt.show()
  469. w_sys_wait_2jdt.wf_accepttol(arg_tableno) //初始化进度条1
  470. w_sys_wait_2jdt.wf_accepttol2(0) //初始化进度条2
  471. for ls_i=1 to arg_tableno
  472. ls_rowsread=0
  473. ls_rowswritten=0
  474. ls_rowsInerror=0
  475. //1.create dw,检查传送数据数目
  476. w_sys_wait_2jdt.st_msg.text="预处理:"+arg_zipfileinfo[ls_i].table_name //进度信息
  477. arg_zipfileinfo[ls_i].table_name=lower(arg_zipfileinfo[ls_i].table_name)
  478. ds_data.reset()
  479. if trim(arg_zipfileinfo[ls_i].table_name)<>"" then
  480. //<1>取出该文件信息
  481. ls_table_name=lower(trim(arg_zipfileinfo[ls_i].table_name))
  482. ll_table_row=ds_tables.find("lower(table_name)= '"+ls_table_name+"'",1,ds_tables.rowcount())
  483. if ll_table_row<=0 then
  484. //重置ds_columns=========
  485. ll_table_id=0
  486. ds_columns.setfilter("")
  487. ds_columns.filter()
  488. //=======================
  489. ls_msg=arg_zipfileinfo[ls_i].table_name+"不在系统记录中;"
  490. arg_log=arg_log+ls_msg+char_enter
  491. table_pipeline_fail++
  492. goto nexttable
  493. end if
  494. ll_table_id=ds_tables.object.table_id[ll_table_row]
  495. //<2>生成select语句
  496. if arg_zipfileinfo[ls_i].dw_creattype = 1 then //直接用filter_string作str_dwSQl
  497. str_dwSQl=arg_zipfileinfo[ls_i].filter_string
  498. else
  499. if arg_zipfileinfo[ls_i].filter_string <> '' then
  500. str_dwSQl="select "+arg_zipfileinfo[ls_i].table_name+".* from "+arg_zipfileinfo[ls_i].table_name + arg_zipfileinfo[ls_i].filter_string
  501. else
  502. str_dwSQl="select "+arg_zipfileinfo[ls_i].table_name+".* from "+arg_zipfileinfo[ls_i].table_name
  503. end if
  504. end if
  505. // SetProfileString("c:\error.txt",'error','a',str_dwSQl)
  506. // messagebox('',str_dwSQl)
  507. //<3>生成DW
  508. ls_msg=""
  509. str_SyntaxFromSQL =itr_source.SyntaxFromSQL(str_dwSQl,"style(type=grid)",ls_msg)
  510. if ls_msg>'' then
  511. arg_msg=arg_zipfileinfo[ls_i].table_name+"dw语法生成失败"
  512. arg_log=arg_log+arg_msg+char_enter
  513. table_pipeline_fail++
  514. goto nexttable
  515. end if
  516. ds_data.Create(str_SyntaxFromSQL,ls_msg)
  517. if ls_msg>'' then
  518. arg_msg=arg_zipfileinfo[ls_i].table_name+"建立相关DW失败"
  519. arg_log=arg_log+arg_msg+char_enter
  520. table_pipeline_fail++
  521. goto nexttable
  522. end if
  523. //<4>DW取数
  524. ds_data.settransobject(itr_source)
  525. w_sys_wait_2jdt.st_msg.text=arg_zipfileinfo[ls_i].table_name+" 正在传递数据..." //进度信息
  526. lg_rowcount=ds_data.retrieve()
  527. //2.建立管道传送数据
  528. ls_table_filterstring=''
  529. if arg_zipfileinfo[ls_i].dw_creattype = 1 then //直接用filter_string作str_dwSQl
  530. ls_table_filterstring=arg_zipfileinfo[ls_i].filter_string
  531. else
  532. if arg_zipfileinfo[ls_i].filter_string <> '' then
  533. ls_table_filterstring=arg_zipfileinfo[ls_i].filter_string
  534. else
  535. ls_table_filterstring=''
  536. end if
  537. end if
  538. ls_createtype=arg_zipfileinfo[ls_i].dw_creattype
  539. if lg_rowcount>0 then //如果有数据
  540. //create PipeLine syntax ================
  541. str_Syntax_PipeLine=''
  542. if p_create_pipesyntax(itr_source,itr_target,arg_commitstep,arg_maxerrors,ll_table_id,ls_table_name,ls_table_filterstring,str_Syntax_PipeLine,arg_msg,ls_createtype)=0 then
  543. arg_log=arg_log+arg_msg+char_enter
  544. table_pipeline_fail++
  545. goto nexttable
  546. end if
  547. //语法赋值给pipeline
  548. invo_pipeline.syntax = str_Syntax_PipeLine
  549. //执行=========================
  550. w_sys_wait_2jdt.wf_accepttol2(lg_rowcount) //初始化进度条2
  551. invo_pipeline.ub_showprocess=true //显示进度条2
  552. invo_pipeline.ul_rowscount=lg_rowcount
  553. // messagebox("",str_Syntax_PipeLine)
  554. ll_pipe_result = invo_pipeline.start(itr_source,itr_target,dw_error)//执行
  555. ls_pipe_result = p_tran_error_mess(ll_pipe_result) //错误信息转换
  556. if ls_pipe_result <> 'OK' then
  557. ls_rowsread=0
  558. ls_rowswritten=0
  559. ls_rowsInerror=0
  560. arg_msg="> 失败>>"+" ["+ls_table_name+"],读出- "+string(ls_rowsread)+",写入- "+string(ls_rowswritten)+",错误- "+string(ls_rowsInerror)+"{"+ls_pipe_result+"}"
  561. table_pipeline_fail++
  562. else
  563. ls_rowsread=invo_pipeline.rowsread
  564. ls_rowswritten=invo_pipeline.rowswritten
  565. ls_rowsInerror=invo_pipeline.rowsInerror
  566. if ls_rowsInerror > 0 then
  567. arg_msg="> 错误>>"+" ["+ls_table_name+"],读出- "+string(ls_rowsread)+",写入- "+string(ls_rowswritten)+",错误- "+string(ls_rowsInerror)
  568. else
  569. arg_msg="> 成功>>"+" ["+ls_table_name+"],读出- "+string(ls_rowsread)+",写入- "+string(ls_rowswritten)+",错误- "+string(ls_rowsInerror)
  570. end if
  571. end if
  572. ls_total_rowsread += ls_rowsread
  573. ls_total_rowswritten += ls_rowswritten
  574. ls_total_rowsInerror += ls_rowsInerror
  575. arg_log=arg_log+arg_msg+char_enter
  576. else
  577. w_sys_wait_2jdt.wf_accepttol2(0) //初始化进度条2
  578. invo_pipeline.ub_showprocess=false
  579. end if
  580. end if
  581. nexttable:
  582. w_sys_wait_2jdt.wf_inc(ls_i) //进度
  583. next
  584. arg_log=arg_log+">>数据传递:表-"+string(arg_tableno)+",其中失败-"+string(table_pipeline_fail)+",数据总读出-"+string(ls_total_rowsread)+",总写入-"+string(ls_total_rowswritten)+",总错误-"+string(ls_total_rowsInerror)+char_enter
  585. //write log
  586. string ls_filepathname
  587. ls_filepathname=sys_cur_path+'exportlog'+'\'+"LongJoe_PipeLine"+string(today(),'yyyymmdd')+string(now(),'hhmmss')+".log"
  588. if arg_if_buildlogfile then
  589. rslt=pf_writetifofile(arg_log,ls_filepathname,arg_msg)
  590. if rslt=0 then
  591. arg_msg="写日志文件失败>>"+arg_msg
  592. rslt=1
  593. end if
  594. end if
  595. close(w_sys_wait_2jdt)
  596. return rslt
  597. end function
  598. on uo_yfimex_pipeline.create
  599. call super::create
  600. TriggerEvent( this, "constructor" )
  601. end on
  602. on uo_yfimex_pipeline.destroy
  603. TriggerEvent( this, "destructor" )
  604. call super::destroy
  605. end on