Skip to content

Doesn't work with Date #13

Closed
Closed

Description

@YamadaHideki
Sub test2()
    Dim d As New Dictionary
    Dim s As String
    
    d.Add CDate("21.02.2025"), "test"
    d.Add CDate("22.02.2025"), "test2"
    
    s = LibJSON.Serialize(d)    ' result: {}
End Sub

Activity

  1. cristianbuse commented on Oct 10, 2025

    @cristianbuse
    Owner

    I've deleted my previous comment. No need to know the region settings. I can replicate. The correct call is:
    s = LibJSON.Serialize(d, forceKeysToText:=True)

    JSON format requires string keys, and so by default, any other type is rejected. There is also the failIfNonTextKeys option. Please see Serializer Options

  2. YamadaHideki commented on Oct 10, 2025

    @YamadaHideki
    Author

    Since the Date data type can be represented as a String in the native VBA, why not automatically represent it without passing parameters, by default?
    BTW: Can I send you a video of an interesting (yet another) Access VBA bug that I can't figure out?

  3. cristianbuse commented on Oct 10, 2025

    @cristianbuse
    Owner

    Since the Date data type can be represented as a String in the native VBA, why not automatically represent it without passing parameters, by default?

    Because this can lead to unwanted behaviour. Plus, most serializers out there do not implicitly cast to string because it's too dangerous.

    BTW: Can I send you a video of an interesting (yet another) Access VBA bug that I can't figure out?

    Please do. Thanks!

  4. YamadaHideki commented on Oct 10, 2025

    @YamadaHideki
    Author

    Since the Date data type can be represented as a String in the native VBA, why not automatically represent it without passing parameters, by default?

    Because this can lead to unwanted behaviour. Plus, most serializers out there do not implicitly cast to string because it's too dangerous.

    BTW: Can I send you a video of an interesting (yet another) Access VBA bug that I can't figure out?

    Please do. Thanks!

    Sended on the email

  5. YamadaHideki commented on Oct 13, 2025

    @YamadaHideki
    Author

    @cristianbuse It seems that my letter is going to spam.

  6. cristianbuse commented on Oct 13, 2025

    @cristianbuse
    Owner

    @YamadaHideki Yeah. I saw that on Friday evening but had no time this weekend. Will have a look today and let you know.

  7. cristianbuse commented on Oct 13, 2025

    @cristianbuse
    Owner

    There must be something confusing the compiler. Do the following replacements make it work?

    1. Dim RowSyncTypeID As Long. VB* implicitly uses 4-byte integer under the hood for a loop
    2. strSql = strSql & "SELECT...". There is an = instead of & in your example.

    Also, what is cGetRows? Is that a function or a global variable? What data type?
    Is EMessageType a class or a struct? Is it from the same project or remote?

  8. YamadaHideki commented on Oct 13, 2025

    @YamadaHideki
    Author

    There must be something confusing the compiler. Do the following replacements make it work?

    1. Dim RowSyncTypeID As Long. VB* implicitly uses 4-byte integer under the hood for a loop
    2. strSql = strSql & "SELECT...". There is an = instead of & in your example.

    Also, what is cGetRows? Is that a function or a global variable? What data type? Is EMessageType a class or a struct? Is it from the same project or remote?

    1. Dim RowSyncTypeID As Long - It won't help, because the code will terminate with an error on a specific line. I showed a piece of code cut out from a large function. In the original function, at the Next operator, a random number is added to the variable, for example, 38, 46, 161, etc.
    2. This is a transfer error; in fact, the string strSql = strSql & “SELECT...” does not solve the problem.

    cGetRows part of the Enum

    ' @description Query method response mode in the cls_Database class
    Enum EDatabaseQueryResultMode2
        cNone                           ' no mode
        cGetRows                        ' array by GetRows
        cFirstColumnAsKeyArray          ' array where the first column is the key in the array
        cFirstColumnAsKeyDictionary     ' dictionary where the first column is the key in the dictionary
        cFirstColumnAsKeyFastDictionary ' dictionary where the first column is the key in the fast dictionary
        cGetRowsAsDictionary            ' array of strings represented as a dictionary
        cGetRowsAsFastDictionary        ' array of strings represented as a fast dictionary
        cOnlyFirstColumnAsArray         ' array of data from the first column only
        cGetRowAsTwoDimensionArray      ' array by GetRows, where the row is a separate array
        cGroupRowsByFirstColumn         ' grouping by the first column
    End Enum
    
    ' @description log types
    Enum EMessageType
        cInfo
        cWarning
        cError
    End Enum

    cls_Logger and EMessageType - references project the same folder as main

  9. cristianbuse commented on Oct 13, 2025

    @cristianbuse
    Owner

    In the original function, at the Next operator, a random number is added to the variable, for example, 38, 46, 161, etc.

    A, ok. This must be a similar stack overlap issue like the ones I fixed for the Dictionary class. This means the issue is somewhere in the sendQuery method of the cls_Database class. To confirm just comment out the code in sendQuery and see if the issue still occurs.

  10. YamadaHideki commented on Oct 13, 2025

    @YamadaHideki
    Author

    In the original function, at the Next operator, a random number is added to the variable, for example, 38, 46, 161, etc.

    A, ok. This must be a similar stack overlap issue like the ones I fixed for the Dictionary class. This means the issue is somewhere in the sendQuery method of the cls_Database class. To confirm just comment out the code in sendQuery and see if the issue still occurs.

    But only official language constructs are used there. Is there any way to fix this? Commenting out the line helps, but it turns out that you can't use functionality from another project.

  11. cristianbuse commented on Oct 13, 2025

    @cristianbuse
    Owner

    No idea if there is a fix. Would you be able to create a minimal example that I can replicate?

    Alternatively, inside the sendQuery method, start commenting lines to narrow the issue. It could be that there is a default property call somewhere. E.g. Collection(3) instead of Collection.Item(3) but on VB class.

  12. YamadaHideki commented on Oct 14, 2025

    @YamadaHideki
    Author

    Не знаю, можно ли это исправить. Не могли бы вы создать минимальный пример, который я смогу воспроизвести?

    В качестве альтернативы, начните комментировать строки внутри sendQueryметода, чтобы сузить область поиска. Возможно, где-то есть вызов свойства по умолчанию. Например, Collection(3) вместо Collection.Item(3), но в классе VB.

    In general, the problem is in the return type. If I copy it and create a new method that returns the copied type, everything works. With the original type, there's a funny thing. This does not work even with an empty body and method parameters.

    ' database response to SQL query in class cls_Database
    Public Type TDatabaseQueryResult
        isCorrect       As Boolean                          ' correct response or error
        info            As String                           ' error information
        resultMode      As EDatabaseQueryResultMode         ' mode in which the result was received
        columnNames     As Scripting.Dictionary                       ' table column names
        result          As Variant                          ' resulting selection
        Count           As Long                             ' number of records returned
        query           As String                           ' sql query
        getRows         As Variant                          ' data from Recordset using the GetRows method
    End Type
    
    Public Type TDatabaseQueryResult2
        isCorrect       As Boolean                          ' correct answer or error
        info            As String                           ' error information
        resultMode      As EDatabaseQueryResultMode         ' in which mode the result was obtained
        columnNames     As Scripting.Dictionary                       ' table column names
        result          As Variant                          ' resulting selection
        Count           As Long                             ' number of records returned
        query           As String                           ' sql query
        getRows         As Variant                          ' data from Recordset using the G method
    End Type
  13. cristianbuse commented on Oct 14, 2025

    @cristianbuse
    Owner

    Does this solve the problem? Replace:
    dbRes = dbConnect.sendQuery(strSql, cGetRows)
    with
    AssignUDT(dbRes) = dbConnect.sendQuery(strSql, cGetRows)
    where you have the additional:

    Private Property Let AssignUDT(ByRef udtLeft As TDatabaseQueryResult, ByRef udtRight As TDatabaseQueryResult)
        udtLeft = udtRight
    End Property
  14. YamadaHideki commented on Oct 14, 2025

    @YamadaHideki
    Author

    Does this solve the problem? Replace: dbRes = dbConnect.sendQuery(strSql, cGetRows) with AssignUDT(dbRes) = dbConnect.sendQuery(strSql, cGetRows) where you have the additional:

    Private Property Let AssignUDT(ByRef udtLeft As TDatabaseQueryResult, ByRef udtRight As TDatabaseQueryResult)
    udtLeft = udtRight
    End Property

    Nope(

  15. cristianbuse commented on Oct 14, 2025

    @cristianbuse
    Owner

    I cannot recreate unfortunately. Do you think you can create a minimal example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions