search
HomeDatabaseMysql TutorialRTP记录log的机制

我们 RCV 这边经常跑的一个concurrent request RTP: Receiving Transaction Processor, 主要是用来处理 RCV_TRANSACTIONS_INTERFACE 里面的数据的. 这个 concurrent program 里面包含许多文件, 比较重要的有: ident RVCTPRVCTP: $Header: rvctp.oc 120.0.120

我们 RCV 这边经常跑的一个concurrent request RTP: Receiving Transaction Processor, 主要是用来处理 RCV_TRANSACTIONS_INTERFACE 里面的数据的.

\

这个 concurrent program 里面包含许多文件, 比较重要的有:

ident RVCTP
RVCTP:
     $Header: rvctp.oc  120.0.12000000.1 2007/01/16 23:53:49 appldev ship $
     $Header: rvtbm.lpc 120.13.12010000.10 2013/03/15 02:51:16 zhlee ship $ 
     $Header: rvtpt.lpc 120.28.12010000.33 2013/07/15 07:12:37 smai ship $
     $Header: rvtvq.lpc 120.8.12010000.17 2013/04/03 11:40:30 wayin ship $
     $Header: rvtuq.lpc 120.9.12000000.7 2009/07/07 09:47:49 YUZZHANG01 ship $
     $Header: pouer.lpc 120.2 2006/06/14 07:57:02 arudas noship $
     $Header: rvtlo.lpc 120.1.12010000.7 2013/01/05 16:02:14 gke ship $
     $Header: rvtoc.lpc 120.1.12010000.5 2013/03/28 22:38:31 vthevark ship $
     $Header: rvtpa.lc  120.6.12010000.3 2009/07/07 08:58:22 ksivasa ship $
     $Header: rvtpd.lc  120.1.12010000.3 2009/07/07 09:03:17 ksivasa ship $
     $Header: rvtsh.lpc 120.10.12010000.3 2009/03/06 22:09:40 vthevark ship $
     $Header: rvtth.lpc 120.29.12010000.9 2012/05/30 15:50:03 gke ship $
     $Header: rvtvt.lpc 120.9.12010000.10 2013/03/28 18:19:11 vthevark ship $
     $Header: rvsco.lpc 120.4.12010000.12 2012/09/27 23:10:24 vthevark ship $
     $Header: rvsrv.lpc 120.4.12010000.16 2013/02/04 07:34:37 zhizheng ship $
     $Header: rvsit.lpc 120.5.12010000.6 2013/02/04 07:26:30 zhizheng ship $
     $Header: rvsdl.lpc 120.5.12010000.17 2011/11/28 05:19:19 xiameng ship $
     $Header: rvssh.lpc 120.2.12010000.3 2009/07/07 09:56:26 ksivasa ship $
     $Header: rvsut.lpc 120.3.12010000.14 2012/05/28 04:53:57 gke ship $
     $Header: rvtcl.lpc 120.6.12010000.3 2009/07/07 09:15:25 ksivasa ship $
     $Header: rvtii.lpc 120.19.12010000.27 2013/08/14 09:58:23 gke ship $
     $Header: rvtls.lpc 120.7.12010000.14 2012/01/30 12:31:22 ksivasa ship $
     $Header: rvtoo.lpc 120.3.12010000.3 2009/07/07 09:08:40 ksivasa ship $
     $Header: rvsrq.lpc 120.5.12010000.3 2009/07/07 09:53:56 ksivasa ship $
     $Header: rvspo.lpc 120.3.12010000.3 2009/07/07 09:53:12 ksivasa ship $

这些文件是在 RTP log 里面经常见到的. 这里我们主要看看, 在这些文件中是用怎样的机制写 log 的.

首先, 要在要写日志的函数里面声明一个变量:

text     strbuf[BUFLEN+1];

然后用下面的语句:

    strcpy((char *)strbuf,"");
    sprintf((char *)strbuf,"RVTUQ:370 req_line_id %ld\n", (long)req_line_id);
    Debug(strbuf,TRUE,TRUE);

第一句把 strbuf 清空, 然后把后面的字符串和整型数写入 strbuf, 第三句 Debug 把 strbuf 写入日志. Debug 后面有两个参数:

#define Debug(message,check_sql_error,no_rows_is_error)

第二个参数 check_sql_error 表示 如果希望检查 SQL error, 就设为 TRUE, 否则设为 FALSE. no_rows_is_error 表示 是不是把 NO_DATA_FOUND 当做一个 error. 如果是, 设为TRUE.

Concurrent Request 里面的文件都是 .c 的代码, 如果里面要写SQL, 就要写一句:

    EXEC SQL
然后下面写上 SQL. 这句 SQL 有可能会出错, 这时需要一个方法把错误消息写到 log 里面去. 比如: 
       EXEC SQL
       select transaction_id,
              unit_of_measure
         into :parent_trx_id,
              :rec_uom
         from rcv_transactions
        where transaction_type in ('RECEIVE','MATCH')
        start with transaction_id = :p_trx_id 
   connect by transaction_id = prior parent_transaction_id;

为了捕获这句SQL 可能发生的错误, 我们在这句后面写一句:

pouersql("RVTUQ", "134", FALSE )
pouersql() 这个函数是在 pouer.lpc 文件 (po user error) 中定义的, 如果上面的SQL 发生了错误, 那么就会把 error message 写入 message stack. 并且返回 true.

这里面有三个参数, routine, location, no_rows_is_err.

routine 表示SQL 发生错误的文件名, 上面的例子中是 RVTUQ.

location 表示SQL 发生错误的位置, 上面的例子中是 134. 这样我们看到日志里面的这个位置就很容易定位到这句SQL.

no_rows_is_err 表示 是不是把 NO_DATA_FOUND 当做 error 来处理. 上面的例子中我们没有当做 error.

在 pouersql 这个函数的内部, 会去sqlca 里面提取 sqlcode. sqlca 全称是: sql communications area, 是一个用来记录SQL 执行信息的地方. 每次执行一个SQL 都会返回 sqlcode. 如果sqlcode = 0, 那么表示没有错误. 如果 sqlcode > 0, 表示有exception, 如果 sqlcode 0, 如果判断小于0, 那么才把错误消息写入 message stack. 如果大于0, 并且参数里面 no_rows_is_err 设为 TRUE, 那么也会写如message stack.

每次执行一次 SQL 就会更新一次 sqlca, 所以这个结构只记录最近一次执行SQL 的信息 . 错误消息是记录在sqlca.sqlerrm.sqlerrmc 里面的. 所以会把这个里面的字符串写入message stack. 但是sqlerrmc 最多只能记录70 个字符, 所以如果错误消息很长的话, 就会被截断.

上面的SQL 发生错误的话, pouersql () 返回值为 TRUE. 那么在调用这个函数的地方, 比如 rvtpt.lpc 文件中, 就会捕捉到这个返回值, 判断返回值之后确定发生error 了, 就会调用:

pouertrace( "RVTUQ", "000", "rvtuqdebitmemo()" )
pouertrace () 这个函数也是在pouer.lpc 文件中定义的, 这个函数的返回值总是 false. 它的主要作用也是把错误消息写入 message stack. 三个参数分别为:

file: 表示发生错误的文件
location: 表示错误的位置
subroutine: 表示发生错误的函数.

上面我们提到, sqlerrmc 只能保存70 个字符. 如果错误消息多余70 个字符, 想要得到所有的错误消息的话, 就需要用 sqlglm() 函数. 在使用这个函数之前, 我们要确保 sqlcode

if (pouersql("RVTUQ","019",TRUE))
{                           
   char msg[510];
   size_t buf_len, msg_len;
   buf_len = sizeof (msg);
   sqlglm(msg, &buf_len, &msg_len);
                
   strcpy((char *)strbuf,"");
   sprintf((char *)strbuf,"RVTUQ:001 YU SQL ERROR %s \n", (text *) msg);
   Debug(strbuf,TRUE,TRUE);
   return( FALSE );
}
sqlglm() 函数把错误消息写入 msg, 然后只要把 msg 用 Debug() 函数写入日志就可以了. sqlglm() 函数对字数也有限制, 最大为512 个字符. 相比 sqlerrmc 的70 个字符多很多了.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools