|
| 1 | +const { Parser } = require('@pgsql/parser'); |
| 2 | +const { ASTTransformer } = require('./dist/transformer'); |
| 3 | + |
| 4 | +async function debugInsertNegative() { |
| 5 | + const parser15 = new Parser(15); |
| 6 | + const parser16 = new Parser(16); |
| 7 | + const transformer = new ASTTransformer(); |
| 8 | + |
| 9 | + const sql = "insert into atacc2 (test2) values (-3)"; |
| 10 | + |
| 11 | + console.log("=== DEBUGGING INSERT NEGATIVE INTEGER ==="); |
| 12 | + console.log("SQL:", sql); |
| 13 | + |
| 14 | + try { |
| 15 | + const pg15Result = await parser15.parse(sql); |
| 16 | + console.log("\n=== PG15 PARSED RESULT ==="); |
| 17 | + console.log(JSON.stringify(pg15Result, null, 2)); |
| 18 | + |
| 19 | + const pg16Result = await parser16.parse(sql); |
| 20 | + console.log("\n=== PG16 PARSED RESULT ==="); |
| 21 | + console.log(JSON.stringify(pg16Result, null, 2)); |
| 22 | + |
| 23 | + const pg15AConst = findAConstInInsert(pg15Result); |
| 24 | + const pg16AConst = findAConstInInsert(pg16Result); |
| 25 | + |
| 26 | + console.log("\n=== PG15 A_Const ==="); |
| 27 | + console.log(JSON.stringify(pg15AConst, null, 2)); |
| 28 | + |
| 29 | + console.log("\n=== PG16 A_Const ==="); |
| 30 | + console.log(JSON.stringify(pg16AConst, null, 2)); |
| 31 | + |
| 32 | + const astToTransform = JSON.parse(JSON.stringify(pg15Result)); |
| 33 | + if (astToTransform.stmts && Array.isArray(astToTransform.stmts)) { |
| 34 | + astToTransform.stmts = astToTransform.stmts.map((stmtWrapper) => { |
| 35 | + if (stmtWrapper.stmt) { |
| 36 | + const transformedStmt = transformer.transform(stmtWrapper.stmt, 15, 16); |
| 37 | + return { ...stmtWrapper, stmt: transformedStmt }; |
| 38 | + } |
| 39 | + return stmtWrapper; |
| 40 | + }); |
| 41 | + } |
| 42 | + astToTransform.version = pg16Result.version; |
| 43 | + |
| 44 | + const transformedAConst = findAConstInInsert(astToTransform); |
| 45 | + console.log("\n=== TRANSFORMED A_Const ==="); |
| 46 | + console.log(JSON.stringify(transformedAConst, null, 2)); |
| 47 | + |
| 48 | + console.log("\n=== COMPARISON ==="); |
| 49 | + console.log("PG15 ival:", JSON.stringify(pg15AConst?.ival)); |
| 50 | + console.log("PG16 ival:", JSON.stringify(pg16AConst?.ival)); |
| 51 | + console.log("Transformed ival:", JSON.stringify(transformedAConst?.ival)); |
| 52 | + |
| 53 | + } catch (error) { |
| 54 | + console.error("Error:", error.message); |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +function findAConstInInsert(obj) { |
| 59 | + if (!obj || typeof obj !== 'object') return null; |
| 60 | + |
| 61 | + try { |
| 62 | + return obj.stmts[0].stmt.InsertStmt.selectStmt.SelectStmt.valuesLists[0].List.items[0].A_Const; |
| 63 | + } catch (e) { |
| 64 | + return null; |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +debugInsertNegative(); |
0 commit comments