Compile Issue under ProCOBOL due to SQLBEX - procobol

Have been trying to compile an existing Pro*COBOL program after making few changes, have verified the syntax and Non-Printable character which may cause issue for compilation.
But at the end, compilation for Pro*COBOL failing due one of .(dot) appearing under CALL to SQLBEX for the embedded SQL (Line Number 18106 under the listing).
See below code for more details, code snippet has been taken from Pro*COBOL code and the listing generated during compilation.
For other instances where SQLBEX is being called, the .(dot) doesn't appear. Would really appreciate any help.
Code under the listing:
18085 IF SQLCODE IN SQLCA = WS-DEADLOCK-WAIT-FOR-RESRC 26825000
18086 SET DEADLOCK TO TRUE 26826000
18087
18088* EXEC SQL 26827000
18089* COMMIT 26828000
18090* END-EXEC
18091 MOVE 1 TO SQL-ITERS
18092 MOVE 2914 TO SQL-OFFSET
* Micro Focus COBOL for UNIX V4.0 revision 004 18-Jan-17 07:31 Page 313
* cmcomc23.cob
18093 MOVE 0 TO SQL-OCCURS
18094 CALL "SQLADR" USING
18095 SQLCUD
18096 SQL-CUD
18097 CALL "SQLADR" USING
18098 SQLCA
18099 SQL-SQLEST
18100 MOVE 256 TO SQL-SQLETY
18101
18102 CALL "SQLBEX" USING
18103 SQLCTX
18104 SQLEXD
18105 SQLFPN
18106 .
18107 26829000
18108 DISPLAY 'DEAD LOCK OCCURED ' 26829100
18109 GO TO 9000-EXIT 26829200
18110 ELSE 26829300
* 562-S****************************************************************( 308)**
** An "ELSE" phrase did not have a matching IF and was discarded.
18111 SET NO-DEADLOCK TO TRUE 26829400
18112 END-IF. 26829500
* 564-S********** ( 313)**
** A scope-delimiter did not have a matching verb and was discarded.
Original Code under Program:
268210******************************************************************26821000
268221 9000-SQL-ERROR SECTION. 26822100
268230******************************************************************26823000
268250 EXEC SQL 26824000
268250 WHENEVER SQLERROR CONTINUE 26824000
268250 END-EXEC. 26824000
268240 26824000
268250 IF SQLCODE IN SQLCA = WS-DEADLOCK-WAIT-FOR-RESRC 26825000
268260 SET DEADLOCK TO TRUE 26826000
268270 EXEC SQL 26827000
268280 COMMIT 26828000
268290 END-EXEC 26829000
268291 DISPLAY 'DEAD LOCK OCCURED ' 26829100
268292 GO TO 9000-EXIT 26829200
268293 ELSE 26829300
268294 SET NO-DEADLOCK TO TRUE 26829400
268295 END-IF. 26829500
268296 26829600
268297 MOVE 'E' TO WS-ERR-SEVERITY-CD. 26829700

Related

"Commands out of sync" error when trying to execute a procedure in MySQL 8

When executing below code in phpMyAdmin:
use db;
DELIMITER $$
DROP PROCEDURE IF EXISTS McaTest3$$
CREATE PROCEDURE McaTest3()
BEGIN
SELECT
cl.*
FROM `condition_library` cl
LEFT JOIN condition_custom cc on cl.condition_library_id = cc.condition_library_id
and cc.active = 1
AND (cc.permit_application_id = 20231 OR cc.permit_id = NULL)
WHERE FIND_IN_SET(cl.`condition_library_id`, '13070')
AND cl.active = 1
and cc.condition_library_id IS NULL;
END$$
DELIMITER ;
call McaTest3();
Getting error:
Error
Static analysis:
1 errors were found during analysis.
Missing expression. (near "ON" at position 25)
SQL query: Edit Edit
SET FOREIGN_KEY_CHECKS = ON;
MySQL said: Documentation
#2014 - Commands out of sync; you can't run this command now
This happens when there is no record found in the table which is at LEFT JOIN.
When the same is ran in MySQL Workbench: NO ERROR and return empty dataset.
Same procedure when executed from Application (Appian) is failing as well… Any clues?
Another question on Stackoverflow answered my issue:
link: MySQL error #2014 - Commands out of sync; you can't run this command now

Executing SQL Script using OSQL do not return resultcode

I am executing some sql queries using OSQL through inno setup. I am using following code to run OSQL. This is just for example purpose
SQLQuery:= '"EXEC sp_addserver ''PCNAME'';"';
Param:= '-S(local) -Usa -Psa -Q ' + SQLQuery;
Exec('osql.exe', Param, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
This works fine. The problem is ResultCode value is always 0. Even if the query does not get executed. For example if I try same query like below where I pass in an invalid stored procedure name the ResultCode is still 0.
SQLQuery:= '"EXEC sp_invalidname ''PCNAME'';"';
Param:= '-S(local) -Usa -Psa -Q ' + SQLQuery;
Exec('osql.exe', Param, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
Why don't this return me a proper code. If I run the second query in management studio I get an error like this
Msg 2812, Level 16, State 62, Line 1
Could not find stored procedure 'sp_invalidname'
Here return code is 2812. Why dont I get this when I run it through inno. What do I need to do to get this error code in inno?
Thanks to TLama, I updated my code as below and its working now. I had to add -b command line parameter and now it returns 1 if the command fails.
-b
Specifies that osql exits and returns a DOS ERRORLEVEL value when an error occurs. The value returned to the DOS ERRORLEVEL variable is 1 when the SQL Server error message has a severity of 11 or greater; otherwise, the value returned is 0. Microsoft MS-DOS batch files can test the value of DOS ERRORLEVEL and handle the error appropriately.
I updated my code as below.
Param:= '-S(local) -Usa -Psa -b -Q ' + SQLQuery;
Its explained in the documentation.

Test the existence of a Teradata table and create the table if non-existent

Our Continuous Inegration server (Hudosn) is having a strange issue when attempting to run a simple create table statement in Teradata.
This statement tests the existence of the max_call table:
unless $teradata_connection.table_exists? :arm_custom_db__max_call_attempt_parameters
$teradata_connection.run('CREATE TABLE all_wkscratchpad_db.max_call_attempt_parameters AS (SELECT * FROM arm_custom_db.max_call_attempt_parameters ) WITH NO DATA')
end
The table_exists? method does the following:
def table_exists?(name)
v ||= false # only retry once
sch, table_name = schema_and_table(name)
name = SQL::QualifiedIdentifier.new(sch, table_name) if sch
from(name).first
true
rescue DatabaseError => e
if e.to_s =~ /Operation not allowed for reason code "7" on table/ && v == false
# table probably needs reorg
reorg(name)
v = true
retry
end
false
end
So as per the from(name).first line, the test which this method is performing is just a simple select statement, which, in SQL, looks like: SELECT TOP 1 MAX(CAST(MAX_CALL_ATTEMPT_CNT AS BIGINT)) FROM ALL_WKSCRATCHPAD_DB.MAX_CALL_ATTEMPT_PARAMETERS
The above SQL statement executes perfectly fine within Teradata SQL Assistant, so it's not a SQL syntax issue. The generic ID which our testing suite (Rubymine) uses is also not the issue; that ID has select access to the arm_custom_db.
The exeption which I can see is being thrown (within the builds console output on Hudson) is
Sequel::DatabaseError: Java::ComTeradataJdbcJdbc_4Util::JDBCException. Since this execption is a subclass of DatabaseError, the exception shouldn't be the problem either.
Also: We use unless statements like this every day for hundreds of different tables, and all except this one work correctly. This statement just seems to be a problem.
The complete error message which appears in the builds console output of Hudson is as follows:
[2015-01-07T13:56:37.947000 #16702] ERROR -- : Java::ComTeradataJdbcJdbc_4Util::JDBCException: [Teradata Database] [TeraJDBC 13.10.00.17] [Error 3807] [SQLState 42S02] Object 'ALL_WKSCRATCHPAD_DB.MAX_CALL_ATTEMPT_PARAMETERS' does not exist.: SELECT TOP 1 MAX(CAST(MAX_CALL_ATTEMPT_CNT AS BIGINT)) FROM ALL_WKSCRATCHPAD_DB.MAX_CALL_ATTEMPT_PARAMETERS
Sequel::DatabaseError: Java::ComTeradataJdbcJdbc_4Util::JDBCException: [Teradata Database] [TeraJDBC 13.10.00.17] [Error 3807] [SQLState 42S02] Object 'ALL_WKSCRATCHPAD_DB.MAX_CALL_ATTEMPT_PARAMETERS' does not exist.
I don't understand why this specific bit of code is giving me issues...there does not appear to be anything special about this table or database, and all SQL code executes perfectly fine in Teradata when I am signed in with the same exact user ID that is being used to execute the code from Hudson.

Fortran formatted write function triggers "has exited with code 408 (0x198)" on IF Composer 2013

When following Fortran code is executed on the Intel Fortran Composer 2013 the compiler triggers a breakpoint at write function and retuns code 408:
character*20 date_char
character*10 LADATE
...
if (date_char(3:3) .EQ. "") date_char(3:3)="0"
if (date_char(7:7) .EQ. "") date_char(7:7)="0"
write(LADATE,"(2A2,A4)")
S date_char(3:4),date_char(7:8),date_char(9:12)
It is a fixed line-length format and the S represents the line continuation.
The date_char has a value of ' 29 012013 ' and the LADATE ' '
As soon as the write statement is reached the debugger triggers a breakpoint and the Call Stack shows following system functions being called:
for_issue_diagnostics()
_for_emit_diagnostics()
Your time is appreciated
The problem was that the LADATE variable was actually a call-by-reference argument (FORTRAN77 default passing convention):
SUBROUTINE MDATE(LADATE)
character*20 date_char
character*10 LADATE
...
write(LADATE,"(2A2,A4)")
S date_char(3:4),date_char(7:8),date_char(9:12)
RETURN
END
and it was passed as an argument several subroutines above as a just an 8-character string. Simply written, the call would be equivalent to:
...
CHARACTER VAR*20
...
CALL MDATE(VAR(10:17))
...
The program started, but after an attempt to access an inaccessible array addresses by the write function the breakpoint was triggered.

How to properly use Alias in Codeigniter

Here is my code:
$this->db->select('course_name AS Course Name,course_desc AS Course Description,display_public AS Display Status',FALSE);
$this->db->from('courses');
$this->db->where('tennant_id',$tennant_id);
$this->db->order_by('course_name','ASC');
$query = $this->db->get();
and I got an error:
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name, course_desc AS Course Description, display_public AS Display Status FROM (' at line 1
and I got an error:
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name, course_desc AS Course Description, display_public AS Display Status FROM (' at line 1
SELECT course_name AS Course Name,
course_desc AS Course Description,
display_public AS Display Status
FROM (`courses`) WHERE `tennant_id` = 'elicuarto#apploma.com'
ORDER BY `course_name` ASC
Filename: C:\wamp\www\coursebooking\system\database\DB_driver.php
Line Number: 330
Try
$this->db->select('course_name AS `Course Name`, course_desc AS `Course Description`, display_public AS `Display Status`', FALSE);
It's the space in your alias that is messing with you.
UPDATE
I'm not sure why you would want to, but I see nothing preventing you from writing
$this->db->select("course_name AS `{$variable}`", FALSE);
(showing just one field for simplicity)
UPDATE 2
Should be standard string conversion so I don't know why it doesn't work for you.. there's always split strings...
$this->db->select('course_name AS `' . $variable . '`', FALSE);

Resources