Advertisement
nBiker77

demo-sql.cbl

Dec 14th, 2024
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. IDENTIFICATION DIVISION.
  2. PROGRAM-ID. CustomerMaria.
  3.  
  4. ENVIRONMENT DIVISION.
  5. CONFIGURATION SECTION.
  6.  
  7. DATA DIVISION.
  8. WORKING-STORAGE SECTION.
  9. 01 DB-HANDLE         USAGE POINTER.
  10. 01 WS-STATUS        PIC 9(9) COMP-5.
  11. 01 WS-MYSQL-VERSION PIC X(20).
  12.  
  13. PROCEDURE DIVISION.
  14. MAIN-PROGRAM.
  15.     DISPLAY "Starting MySQL connection test..."
  16.  
  17.     *> Verificar versión de MySQL
  18.     CALL "mysql_get_client_info"
  19.         USING BY REFERENCE WS-MYSQL-VERSION
  20.         ON EXCEPTION
  21.             DISPLAY "ERROR: Cannot get MySQL version"
  22.             PERFORM PROGRAM-END
  23.     END-CALL
  24.     DISPLAY "MySQL Client Version: " FUNCTION TRIM(WS-MYSQL-VERSION)
  25.  
  26.     *> Inicializar puntero
  27.     SET DB-HANDLE TO NULL
  28.     DISPLAY "Initial DB-HANDLE: " DB-HANDLE
  29.  
  30.     *> Intentar inicializar MySQL
  31.     CALL "mysql_init"
  32.         USING BY REFERENCE DB-HANDLE
  33.     MOVE RETURN-CODE TO WS-STATUS
  34.  
  35.     DISPLAY "Status after init: " WS-STATUS
  36.     DISPLAY "DB-HANDLE after init: " DB-HANDLE
  37.  
  38.     IF DB-HANDLE = NULL
  39.         DISPLAY "mysql_init failed - NULL handle returned"
  40.     ELSE
  41.         DISPLAY "mysql_init successful - attempting connection"
  42.  
  43.         *> Intentar conexión
  44.         CALL "mysql_real_connect"
  45.             USING BY REFERENCE DB-HANDLE
  46.                   BY CONTENT z"localhost"
  47.                   BY CONTENT z"testuser"
  48.                   BY CONTENT z"testpassword"
  49.                   BY CONTENT z"customer_db"
  50.                   BY VALUE 0
  51.                   BY VALUE 0
  52.                   BY VALUE 0
  53.         END-CALL
  54.         MOVE RETURN-CODE TO WS-STATUS
  55.  
  56.         IF WS-STATUS = 0
  57.             DISPLAY "Connection failed"
  58.         ELSE
  59.             DISPLAY "Connection successful"
  60.         END-IF
  61.     END-IF
  62.  
  63.     PERFORM PROGRAM-END.
  64.  
  65. PROGRAM-END.
  66.     IF DB-HANDLE NOT = NULL
  67.         CALL "mysql_close"
  68.             USING BY REFERENCE DB-HANDLE
  69.         END-CALL
  70.         DISPLAY "Connection resources freed"
  71.     END-IF
  72.     STOP RUN.
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement