Skip to content

Conversation

@renanwilliam
Copy link

Summary

  • Add support for separate Node.js and Java character encoding configuration
  • Fixes issue with special characters (accents, cedillas, etc.) when connecting to databases using legacy encodings like Windows-1252
  • Maintains 100% backward compatibility

Problem Solved

Resolves issue #46 where special characters are not handled correctly due to encoding mismatches between Java and Node.js components.

Changes Made

Core Implementation

  • SybaseDB.js: Added optional javaEncoding parameter to constructor options
  • Main.java: Added constructor overload to accept encoding parameter (preserves existing constructor)
  • StdInputReader.java: Added constructor with encoding support, falls back to default on error
  • Java Process: Automatically passes -Dfile.encoding JVM parameter when javaEncoding is specified

Testing & Documentation

  • test_encoding.js: Comprehensive Mocha/Chai tests covering all encoding scenarios
  • README.md: Complete documentation with usage examples and common encoding combinations
  • JavaSybaseLink.jar: Recompiled with encoding support

New API Usage

var Sybase = require('sybase');
var db = new Sybase('host', port, 'dbName', 'username', 'password', false, null, {
    encoding: 'latin1',     // Node.js IPC encoding 
    javaEncoding: 'Cp1252', // Java database communication encoding
    extraLogs: false
});

// Now queries with special characters work correctly
db.query('SELECT * FROM usuarios WHERE nome = "José"', callback);

Common Use Cases

  • Windows-1252 databases: encoding: 'latin1', javaEncoding: 'Cp1252'
  • ISO-8859-1 databases: encoding: 'latin1', javaEncoding: 'ISO-8859-1'
  • UTF-8 databases: No changes needed (default behavior)

Backward Compatibility

✅ All existing code continues to work without changes
✅ New parameters are optional
✅ Java constructors use method overloading (no breaking changes)
✅ Default behavior unchanged

Test Results

  • ✅ 8 new tests passing (encoding functionality)
  • ✅ All existing functionality preserved
  • ✅ No breaking changes detected

🤖 Generated with Claude Code

Fixes issue with special characters (accents, cedillas) when connecting
to databases using legacy encodings like Windows-1252.

Changes:
- Add optional javaEncoding parameter to SybaseDB constructor
- Pass -Dfile.encoding to Java process when javaEncoding is specified
- Update Java classes to accept encoding parameter with full backward compatibility
- Add comprehensive Mocha/Chai tests for encoding functionality
- Update documentation with encoding usage examples

The new API allows separate control of Node.js IPC encoding and Java
database encoding, resolving character encoding mismatches while
maintaining 100% backward compatibility.

Usage:
new Sybase(host, port, db, user, pass, false, null, {
  encoding: 'latin1',     // Node.js IPC encoding
  javaEncoding: 'Cp1252'  // Java database encoding
});

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Windows-1252/CP1252 database encoding - Java and Node.js encoding mismatch

1 participant