cpp-libp2p icon indicating copy to clipboard operation
cpp-libp2p copied to clipboard

Code Quality Improvements: SQLite Wrapper Enhancements

Open alienx5499 opened this issue 4 months ago • 1 comments

Summary

This PR improves code quality by adding const correctness, better error handling, and additional utility methods to the SQLite wrapper class.

Changes

  • include/libp2p/storage/sqlite.hpp: Enhanced method declarations with const correctness and better documentation
  • src/storage/sqlite.cpp: Improved implementations with better error handling and new utility methods

Methods Updated

  • getErrorCode() - Returns SQLite extended error code (const)
  • getErrorMessage() - Returns human-readable error message (const)
  • countChanges() - Returns number of rows modified (const)
  • getDatabaseFile() - Returns database file path (const, new)
  • getStatementCount() - Returns number of prepared statements (const, new)
  • getStatement() - Improved error messages with detailed handle information
  • execCommand() - Better error handling and documentation
  • execQuery() - Better error handling and documentation

Benefits

  • Better API Design: Methods that don't modify state are properly marked as const
  • Improved Error Handling: More descriptive error messages and proper exception handling
  • Enhanced Debugging: New utility methods for database file path and statement count
  • Code Clarity: Better documentation and more informative error messages
  • C++ Best Practices: Follows modern C++ const correctness and exception safety guidelines
  • Better Exception Safety: Proper re-throwing of programming errors vs runtime errors

Testing

  • No breaking changes - all improvements are additive
  • Existing functionality remains unchanged
  • New utility methods provide additional debugging capabilities
  • Improved error messages help with troubleshooting

alienx5499 avatar Sep 06 '25 12:09 alienx5499

@turuslan Could you please review this PR when you get a chance?

alienx5499 avatar Sep 09 '25 12:09 alienx5499