正在进行4GL修复102亿SQL长度误差(Fixing sql length error in pr

2019-09-21 07:46发布

我试图使用openedge JDBC连接器拉从现有进度分贝运行到列宽度问题的数据,但即时通讯。

这里是抱着我的错误。

[DataDirect的] [OpenEdge JDBC驱动程序] [OpenEdge]柱TabDisplayName在表PUB.Menu具有值超过其最大长度或精度。

我已经看了很多帖子,各有各的意见,这里是我给什么远一走这样的:

  1. 手动修改通过所述数据字典中的SQL宽度。
    • 我跑PUB.Menu.TabDisplayName快速检查发现的44个字符的最大值
    • 宽度到x(50),没有运气再次设置无济于事,然后X(100)出不合理的愤怒的修复。
  2. 使用SUBSTR()SQL函数以截断场
    • 我得到这个奇怪的结果。 它在sqlexp但它像永远不会选择列在Java环境中正常工作。
  3. 使用dbtool自动修复宽度问题,选项#2
    • 选择所有表和“区域”后(不知道这些是什么......),并提交仿佛什么都没有发生过,我回到了proenv CMDLINE最后的选项。
  4. 经由4GL编程修改SQL宽度
    • 这是我发现我还没有尝试的唯一选择。
    • 我有点不愿意尝试这不仅是因为手动修改失败。 另外这是一个活生生的开发环境(仅适用于我),我试着去搞砸了太多苦头,虽然我经常服用卡扣。

在UNIX机器上运行进度102亿。

任何意见和建议,将不胜感激。

-谢谢

Answer 1:

该dbtool选择是最好的。 它是专为这一点。 从proenv你应该看到这样的事情:

proenv> dbtool S2K

  DATABASE TOOLS MENU - 10.2B --------------------------- 1. SQL Width & Date Scan w/Report Option 2. SQL Width Scan w/Fix Option 3. Record Validation 4. Record Version Validation 5. Read or Validate Database Block(s) 6. Record Fixup 7. Schema Validation 9. Enable/Disable File Logging Q. Quit Choice: 2 

:(0 =单用户1 =自助服务> 1 =#线程)? 1

填充%当前最大值以上:100

(表号或全部)? 所有

(区号码或全部)? 所有

(详细级别0-3)? 0

总记录阅读:31357

发现SQLWidth错误:0,发现日期错误:0

SQLWidth错误修正:0

如果你的数据库有一个服务器最多和运行选择“1”的连接:提示。 如果没有,选择“0”。

挑100填充,以字段的宽度的两倍。

尝试在“体育”数据库的副本,如果你不确定。 如果你想要一些洞察到它是做什么用冗长外的一个更高的水平。

它并不需要很长时间在一个小的开发数据库运行。 (这是在“运动”基本上是瞬间的。)



Answer 2:

它可以创建子(field.name,1,最大长度)的选项视图,并使用PUB2.viewname代替pub.tablename

    DROP VIEW PUB2."accounts";
    CREATE VIEW PUB2."accounts" ( 
    "ACC-TYPE",
    "ACCOUNT-NAME",
    ANALITIC,
    ARCH,
    COUNT1,
    CURRENCY,
    PLAN,
    QUANTITY,
    "RID-ANOBJECT",
    "RID-APP",
    TRANSIT ) 
    AS select "acc-type",
    SUBSTRING("account-name", 1, 130),
    "analitic",
    "arch",
    "count1",
    "currency",
    "plan",
    "quantity",
    "rid-anobject",
    "rid-app",
    "transit"
    FROM PUB."accounts";
    COMMIT;

使用sqlexp自动创建:sqlexp帐户-H本地主机-S '+分贝端口+' -user sysprogress -password sysprogress -infile recreateSQLviews.sql -outfile recreateSQLviews.log

这里是代码:

    def var num-port as integer.
    for first _Servers where _Servers._Server-Type = "Login" no-lock:
        num-port = _Servers._Server-PortNum.
    end.
    if num-port < 0 then num-port = num-port + 65536.
    if num-port = 0 then do:
       message "Define -S parameter for Database" view-as alert-box.
       RETURN.
    end.
    message num-port.

    /* ttSQLWidth table: SQL WIDTH for all tables */

    def var execstr as char.
    def var rez-str as char.
    def var db-port as char. /* -S port */
    db-port = STRING(num-port).

    DEFINE TEMP-TABLE ttSQLWidth NO-UNDO
        FIELD tableName   AS CHARACTER
        FIELD tableNum    AS INTEGER
        FIELD fieldName   AS CHARACTER
        FIELD sqlWidth    AS INTEGER
        FIELD requireFix  AS LOGICAL INIT FALSE
        FIELD actualWidth AS INTEGER
        FIELD newWidth    AS INTEGER
    INDEX tableNum  tableNum
    INDEX tableName tableName.

    FOR EACH _File NO-LOCK WHERE _Tbl-Type = "T":
        FOR EACH _Field OF _File WHERE _Field._Data-type = "character":
            if _field._extent > 0 then next.
            CREATE ttSQLWidth.
            ASSIGN tableName = _File._File-name
                tableNum = _File._File-num
        fieldName = _Field._Field-name
        sqlWidth = _Field._Width.
        RELEASE ttSQLWidth.
        END. /* FOR EACH _Field */
    END. /* FOR EACH _File */

    DEFINE VARIABLE bTab        AS HANDLE      NO-UNDO.
    DEFINE VARIABLE hQuery      AS HANDLE      NO-UNDO.
    DEFINE VARIABLE queryString AS CHARACTER   NO-UNDO.

    FOR EACH ttSQLWidth:
        CREATE BUFFER bTab FOR TABLE tableName.
        CREATE QUERY hQuery.
        hQuery:ADD-BUFFER(bTab).

        message tablename.
        queryString = "FOR EACH " + tableName + " WHERE LENGTH(" + fieldName + ") >= " + STRING(sqlWidth) + " BY LENGTH(" + fieldName + ") DESC".
        hQuery:QUERY-PREPARE(queryString).
        hQuery:QUERY-OPEN().

        IF hQuery:GET-NEXT() THEN DO:
            ASSIGN actualWidth = LENGTH(bTab:BUFFER-FIELD(fieldName):BUFFER-VALUE)
                   requireFix = TRUE.
        END. /* IF .. THEN DO */

        hQuery:QUERY-CLOSE.
        DELETE OBJECT hQuery.

        bTab:BUFFER-RELEASE().
        DELETE OBJECT bTab.

    END. /* FOR EACH ttSQLWidth */

    def var add-pr   as integer initial 10.  /* % from max */
    def var maxWidth as integer initial 249. /* maxwidth */

    FOR EACH ttSQLWidth WHERE ttSQLWidth.requireFix = TRUE:

        ttSQLWidth.newWidth = TRUNCATE ( (ttSQLWidth.actualWidth + add-pr) / add-pr, 0 ) * add-pr.
        ttSQLWidth.newWidth = INTEGER( ttSQLWidth.newWidth).
        if ttSQLWidth.newWidth > maxWidth then ttSQLWidth.newWidth = maxWidth.

    END.

    /* sql script generation */ 

    OUTPUT TO value("recreateSQLviews.sql").
    def var lst-field as char.
    FOR EACH ttSQLWidth WHERE BREAK BY ttSQLWidth.tableName:
       IF FIRST-OF(ttSQLWidth.tableName) 
          THEN run MakeSQLViews(ttSQLWidth.tableName).

    END.
    OUTPUT CLOSE. 

    /* sql script execution */

    execstr = 'sqlexp account -H localhost -S ' + db-port + ' -user sysprogress -password sysprogress -infile recreateSQLviews.sql -outfile recreateSQLviews.log'.

    input through value(execstr).
    repeat:
      IMPORT UNFORMAT rez-str.
      message rez-str.
    end.
    INPUT CLOSE.

    RETURN.

    PROCEDURE MakeSQLViews:
    define input parameter tableName as character.

    def var str_tmp as char.
    def var str_tmp1 as char.
    def var str as char initial "count,sum,double,row,date,level,area,number,primary".

    def var fieldName  as char.
    def var fieldName1 as char.

    FOR EACH _file WHERE _file._file-name = tableName AND 
                         _file._file-num GT 0 AND _file._file-num LT 32000 NO-LOCK:   
       fieldName = "".    
       FOR EACH _Field OF _File NO-LOCK:            

              str_tmp = '"' + _Field._Field-name + '"'.
              FOR FIRST ttSQLWidth where ttSQLWidth.tableName = _file._file-name   and 
                                         ttSQLWidth.fieldName = _Field._Field-name and 
                                         ttSQLWidth.requireFix = TRUE:
                  str_tmp = 'SUBSTRING("' + _Field._Field-name + '", 1, ' + STRING(ttSQLWidth.newWidth) + ')'. 
              END.
              fieldName  = fieldName + (IF(fieldName = "") THEN ("") ELSE ("," + chr(10) + chr(9))) + str_tmp.    
              str_tmp1   = ( IF ( INDEX ( _Field._Field-name, "-" ) = 0 ) 
                                THEN ( _Field._Field-name ) 
                                ELSE ( '"' + _Field._Field-name + '"' )).

              if LOOKUP ( _Field._Field-name, str, "," ) > 0 then str_tmp1 = '"' + _Field._Field-name + '"'.

              fieldName1 = fieldName1 + (IF(fieldName1 = "") THEN ("") ELSE ("," + chr(10) + chr(9))) + UPPER(str_tmp1). 

       END. /* FOR EACH _Field */    

       PUT UNFORMATTED 'DROP VIEW PUB2."' + _file._file-name + '";' SKIP.     
       PUT UNFORMATTED 'CREATE VIEW PUB2."' + _file._file-name + '" ( ' + chr(10) chr(9) + fieldName1 +  ' ) ' + chr(10) + 
           'AS select ' + fieldName + chr(10) + 
           'FROM PUB."' + _file._file-name + '";' SKIP.     
       PUT UNFORMATTED 'COMMIT;' SKIP(1). 
    END.

    END.


文章来源: Fixing sql length error in progress 4gl 10.2B