![](/img/trans.png)
[英]Is it possible to get information where a variable, handle, buffer are defined?
[英]How to use `export` with buffer handle?
在删除表之前导出表的数据就像一个魅力。
例子 :
OUTPUT TO VALUE("C:\mytable.d") APPEND.
EXPORT mybd.mytable.
OUTPUT CLOSE.
DELETE mybd.mytable.
但是,我还没有让它在使用缓冲区句柄时起作用。 下面导出一个整数而不是删除的数据。
DEF INPUT PARAM hlTableToDelete AS HANDLE NO-UNDO.
...
OUTPUT TO VALUE("C:\" + hiTableToDelete:NAME + ".d") APPEND.
EXPORT hlTableToDelete:HANDLE.
OUTPUT CLOSE.
hlTableToDelete:BUFFER-DELETE().
命令export
需要哪种语法才能工作并实际导出缓冲区句柄的数据?
EXPORT 仅适用于静态缓冲区。 缓冲区句柄没有 EXPORT 方法。
要获得等效的功能,您需要编写一些循环遍历字段列表的代码。
沿着这些路线的东西应该让你开始:
/* export data like EXPORT does
*
* makes no attempt to handle LOB data types
*
*/
function exportData returns logical ( input bh as handle ):
define variable bf as handle no-undo. /* handle to the field */
define variable f as integer no-undo. /* field number */
define variable i as integer no-undo. /* array index */
do f = 1 to bh:num-fields: /* for each field... */
bf = bh:buffer-field( f ). /* get a pointer to the field */
if f > 1 then put stream expFile unformatted field_sep. /* output field separator */
if bf:extent = 0 then /* is it an array? */
put stream expFile unformatted
( if bf:data-type = "character" then /* character data needs to be quoted to */
quoter( string( bf:buffer-value )) /* handle (potential) embedded delimiters */
else /* and quotes within quotes! */
string( bf:buffer-value ) /* other data types should not be quoted */
)
.
else /* array fields need special handling */
do i = 1 to bf:extent: /* each extent is exported individually */
if i > 1 then put stream expFile unformatted field_sep. /* and a field separator */
put stream expFile unformatted
( if bf:data-type = "character" then /* see above... */
quoter( string( bf:buffer-value( i )))
else
string( bf:buffer-value( i ))
)
field_sep
.
end.
end.
put stream expFile skip. /* don't forget the newline! ;-) */
return true.
end.
Tom 例程的较短版本,用于处理具有相同代码路径的范围字段和普通字段。
function exportBuffer returns logical ( input bh as handle ):
define variable bf as handle no-undo.
define variable f as integer no-undo.
define variable i as integer no-undo.
do f = 1 to bh:num-fields:
bf = bh:buffer-field( f ).
do i = if bf:extent = 0 then 0 else 1 to bf:extent:
put stream expFile unformatted
(
if bf:data-type = "character" then
quoter( string( bf:buffer-value( i ) ) )
else
string( bf:buffer-value( i ) )
)
(
if f = bh:num-fields and i = bf:extent then
""
else
field_sep
)
.
end.
end.
put stream expFile skip.
return true.
end.
https://abldojo.services.progress.com:443/#/?shareId=5d5643554b1a0f40c34b8bed
如果真的,真的,真的,真的需要,我只会使用专有的导出语句格式,在任何其他情况下,我都会使用内置的序列化方法( write-xml
/ write-json
)。 除了正确转义特殊字符之外,它们还以全世界都能理解的格式导出所有数据。
这很有帮助! 在我的测试中,我发现此代码不适用于带有 DATETIME 字段的 IMPORT 命令; 这是我用来按照 IMPORT 预期的方式对其进行格式化的代码:
CASE FieldHandle:data-type:
WHEN "datetime" THEN
DO:
OutStr = STRING(FieldHandle:BUFFER-VALUE,"99-99-9999THH:MM:SS.SSS").
IF OutStr <> ? THEN
OutStr = SUBSTRING(OutStr,7,4) + "-" + SUBSTRING(OutStr,1,5) + SUBSTRING(OutStr,11).
PUT STREAM snapshot UNFORMATTED OutStr.
END.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.