Word64 does not roundtrip through a database correctly

オープン
#1,552 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
haskell
領域
databases

調査の方向性

まず、Haskell Word64 PersistField instance と、対応するデータベースバックエンドで使用されている PersistValue の処理を見つけます。issue で説明されている SQLite の動作を参考にして、各バックエンドが Int64 を超える値をどのように保存し、並べ替えるかを比較します。対応するすべてのデータベースで Word64 値が正しい値とソート順を保持すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Bug Reports

The Word64 instance for PersistField does not roundtrip through databases correctly.
It uses fromIntegral for converting between Word64 and Int64.

While this does technically roundtrip, the database values will be silently wrong because negative values will be saved instead of positive ones.

Example:

This does technically roundtrip:

ghci> import Data.Word
ghci> import Data.Int
ghci> 2^64
18446744073709551616
ghci> fromIntegral (18446744073709551615  :: Word64) :: Int64
-1
ghci> fromIntegral (-1 :: Int64) :: Word64
18446744073709551615

BUT the database will contain -1, which does not sort in the same way.

Solutions

You could have another PersistValue constructor for Word64, but I'm not sure if all the "supported" databases support such a type.
As far as I can tell, sqlite supports larger integers by storing them as reals but I don't know about other databases:

sqlite> create table t1 (i INTEGER);
sqlite> insert into t1 values(18446744073709551615);
sqlite> insert into t1 values(0);
sqlite> insert into t1 values(1);
sqlite> select * from t1 order by i;
0
1
1.84467440737096e+19
sqlite> select typeof(i) from t1;
real
integer
integer
主要言語
Haskell
スター
486
フォーク
307
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

yesodweb/persistent のほかの issue

yesodweb/persistent の issue をすべて見る

似ている issue

Haskell の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。