Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding integer data value from application is broken for WP(8) #123

Closed
brodycj opened this issue Aug 21, 2014 · 5 comments
Closed

Binding integer data value from application is broken for WP(8) #123

brodycj opened this issue Aug 21, 2014 · 5 comments

Comments

@brodycj
Copy link
Contributor

brodycj commented Aug 21, 2014

If an application using the WP(8) version inserts an integer value into a column for which no type was specified, and then the same value is retrieved, the value will be returned to the application as a string. In the following test case:

db.transaction(function(tx) {
  // create columns with no type affinity
  tx.executeSql("insert into test_table (data_text, data_int, data_real) VALUES (?,?,?)",
      ["3.14159", 314159, 3.14159], function(tx, res) {
    equal(res.rowsAffected, 1, "row inserted");
    tx.executeSql("select * from test_table", [], function(tx, res) {
      start();
      var row = res.rows.item(0);
      strictEqual(row.data_text, "3.14159", "data_text should have inserted data as text");
      strictEqual(row.data_int, 314159, "data_int should have inserted data as an integer");
      ok(Math.abs(row.data_real - 3.14159) < 0.000001, "data_real should have inserted data as a real");
    });
  });
});

the strictEqual() check on data_int fails on the WP(8) version.

@brodycj brodycj added the bug label Aug 21, 2014
@Typhlosaurus
Copy link

This appears to be because of bug in WP8 code (trivial to fix - changing
string[] to object[]) and a problem with the JSON deserialiser (harder to
fix). When told to deserialise ['1.1', 1] as object[] it deserialises it
as [1.1, 1]. The same code running on the PC version of .Net 4
deserialises it as expected.

On 21 August 2014 03:10, Chris Brody notifications@github.com wrote:

If an application using the WP(8) version inserts an integer value into a
column for which no type was specified, and then the same value is
retrieved, the value will be returned to the application as a string. In
the following test case:

db.transaction(function(tx) {
// create columns with no type affinity
tx.executeSql("insert into test_table (data_text, data_int, data_real) VALUES (?,?,?)",
["3.14159", 314159, 3.14159], function(tx, res) {
equal(res.rowsAffected, 1, "row inserted");
tx.executeSql("select * from test_table", [], function(tx, res) {
start();
var row = res.rows.item(0);
strictEqual(row.data_text, "3.14159", "data_text should have inserted data as text");
strictEqual(row.data_int, 314159, "data_int should have inserted data as an integer");
ok(Math.abs(row.data_real - 3.14159) < 0.000001, "data_real should have inserted data as a real");
});
});});

the strictEqual() check on data_int fails on the WP(8) version.


Reply to this email directly or view it on GitHub
#123.

@brodycj
Copy link
Contributor Author

brodycj commented Aug 21, 2014

On Thu, Aug 21, 2014 at 12:31 PM, Typhlosaurus notifications@github.com
wrote:

This appears to be because of bug in WP8 code (trivial to fix - changing
string[] to object[])

👍

and a problem with the JSON deserialiser (harder to
fix). When told to deserialise ['1.1', 1] as object[] it deserialises it
as [1.1, 1].

I consider this to be very minor - I cannot see how this would cause any
data preservation or integrity issues. I will just document this one.

brodycj pushed a commit that referenced this issue Aug 22, 2014
… WP(8) open/close/delete issues (ref: #109/#110/#112); fix integer data binding (#123); credit for WP(8) fixes to mark.oppenheim@mnetics.co.uk
@briancalvillo
Copy link

This code is worked for me, in the SQLitePlugin.cs when the query has REAL values:

        public void executeSqlBatch(DBQuery dbq)
        {
            string batchResultsStr = "";

            System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
            customCulture.NumberFormat.NumberDecimalSeparator = ".";

            System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;

@brodycj
Copy link
Contributor Author

brodycj commented Aug 29, 2014

Hi @briancalvillo I think your code above addresses a different problem that if a device has a European culture configuration it could cause a REAL number to be formatted incorrectly in the result that is returned to the Javascript, causing the application code to receive incorrect data. I must admit that my C# knowledge is not so great (the WP(8) version was implemented by @marcucio) so this is only speculation. I found a couple links that may be relevant:

brodycj pushed a commit that referenced this issue Aug 29, 2014
@briancalvillo suggested a possible fix using
System.Globalization.CultureInfo in #123. This _could_ be needed on
devices with European localization. Using CultureInfo.InvariantCulture
in both Convert.ToDouble() and String.Format() for REAL (Double) results
to be extra-safe.
brodycj pushed a commit that referenced this issue Aug 29, 2014
…ation issue in WP(8) REAL result to Javascript (ref: #123)
@brodycj
Copy link
Contributor Author

brodycj commented Aug 29, 2014

Now fixed inmaster (version 1.0.1)

@brodycj brodycj closed this as completed Aug 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants