读取和执行在COBOL SQL语句

首先,如果有遗憾媒体链接被问,我彻底搜查,但似乎无法找到答案。

这是为学校的一个项目,我们认识到,这可能在一个更有效的方式来解决,但是这不是一个选项。

因此,这里的问题是:

  1. 我们必须使用Microsoft SQL Server 2008 R2,在这里我们有一个空数据库。
  2. 使用COBOL语言中,我们必须创建所有的表,使用参数文件sqlstatements.sql(AI阅读每个语句,执行它们,等等。

我们我们遇到(和甚至我们的老师解决不了大气压)的问题是:

  1. 在一个非常奇怪的方式正在读取SQL语句(语句被随机扰码)
  2. 我们似乎没有任何权利来实际编辑数据库。

这里是COBOL代码:

IDENTIFICATION DIVISION. PROGRAM-ID. DB_connection. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT sqlscript assign to "databaseScript.sql" ORGANIZATION IS LINE SEQUENTIAL. SELECT logfile assign to "logfile.txt" ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD sqlscript. 01 sqlstatement. FD logfile. 01 logrecord. 03 logline pic x(100). WORKING-STORAGE SECTION. EXEC SQL BEGIN DECLARE SECTION END-EXEC * SQLCODE is 0 for success, 100 for no data, -1 for failure 01 SQLCODE PIC S9(3). * SQLSTATE is a 5 character communication code; 00xxx is success. 01 SQLSTATE PIC X(5). 01 JdbcString PIC X(255). EXEC SQL END DECLARE SECTION END-EXEC 01 einde pic X value '0'. 88 einde-bestand value '1'. PROCEDURE DIVISION. MAIN-PARAGRAPH. * Initial code OPEN INPUT sqlscript OPEN EXTEND logfile PERFORM DO-CONNECT DISPLAY "After connecting to the database:" DISPLAY "SQLCODE= " + SQLCODE. DISPLAY "SQLSTATE= " + SQLSTATE DISPLAY "Connectie met java succes." IF sqlcode = 0 MOVE "Connectie succesvol" to logline WRITE logrecord DISPLAY "Writing to logfile" END-IF PERFORM LEESSQLBESTAND * lees sql bestand, read entry'sz * Use the database CLOSE sqlscript CLOSE logfile PERFORM DO-DISCONNECT ACCEPT SQLSTATE * Terminate the program GOBACK * The SQL connect statement must be completed with the information * appropriate to the actual JDBC driver in use. JDBC stands for * Java DataBase Connectivity, and it is the method by which PERCobol * accesses databases and database-like data sources. * * The JDBC driver itself must be included in the Java library path * in order to successfully connect to the database. The JDBC driver * is generally included with the database itself; see the database * documentation for more details. * * When connecting to a datasource, the jdbc:url may be * ds:data-source-name. * * jdbc:url The JDBC url to the database itself * com.driver.name This is the classname of the driver * DO-CONNECT. STRING "jdbc:sqlserver://localhost\SQLEXPRESS;" DELIMITED BY SIZE "databaseName=ProjectManagement;" DELIMITED BY SIZE "userName=admin;password=broforce" DELIMITED BY SIZE INTO JdbcString EXEC SQL CONNECT TO :JdbcString DRIVER "com.microsoft.sqlserver.jdbc.SQLServerDriver" END-EXEC. LEESSQLBESTAND. READ sqlscript AT END DISPLAY 'LEEG SQL BESTAND' MOVE '1' TO einde MOVE "Leeg SQL-Bestand" to logline NOT AT END DISPLAY 'MINSTENS 1 SQL STATEMENT' MOVE "Queries found..." to logline END-READ WRITE logrecord PERFORM UNTIL einde = 1 MOVE sqlstatement to logline EXEC SQL EXECUTE sqlstatement END-EXEC IF sqlcode < 0 move "failed" to logline WRITE logrecord END-IF IF sqlcode = 0 move "succes" to logline WRITE logrecord END-IF READ sqlscript AT END DISPLAY 'EINDE SQL BESTAND' MOVE '1' TO einde MOVE "Einde Bestand" to logline END-READ WRITE logrecord EXEC SQL COMMIT WORK END-EXEC END-PERFORM * Disconnect from the SQL database connection. This allows the * JDBC driver to free any resources required for the connection. DO-DISCONNECT. EXEC SQL DISCONNECT END-EXEC.

难道我做错了什么吗? 我们是处于亏损状态。

--------------解决方案-------------

COBOL是面向固定长度的记录,但它可以轻松地处理可变长度的记录。

...
FD sqlscript
record is varying in size
depending on sqlstatement-length.
01 sqlstatement.
05 filler pic x occurs 0 to 9999 times
depending on sqlstatement-length.
...
working-storage
...
01 sqlstatement-length pic 9(4) binary.
...
procedure division.
...
read sqlscript
*then you can use sqlstatement-length to grab what you need
*you might want to add if sqlstatement-length = zero logic for blank lines
move sqlstatement(1:sqlstatement-length) to wherever

随机扰码,假设我解释这是什么意思正确,通常意味着你要么需要初始化变量,你正在阅读中(剩余数据废弃,另外添购你的工作存储),或者你移动不兼容的类型或错误之间的数据-sized领域。 既然你有你的SQLStatement(如何,即使工作?)没有图片子句就很难说有什么不对劲的地方。

至于权限去,我只经历过在IBM / DB2环境,但我总是要得到我的DB2本身单独的程序,使其可以修改我的基地设置权限。

分类:SQL 时间:2015-03-14 人气:0
本文关键词: 数据库,SQL,COBOL
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.705 (s). 10 q(s)