4

データベースに 240 バイト (1920 ビット) のバイナリ文字列を格納しています (現在は MySQL ですが、データベースに依存したくない)。

次のことを行う必要があります。

UPDATE `my_table` SET `data` = `data` ^ 'new_data' WHERE `id` = 'field_id'

SQL 構文のビット単位の XOR は、最大 6b ビットの値に対してのみ機能すると思います。

テキスト フィールドに 16 進エンコーディングを使用してデータを格納していますが、必要に応じてこれをバイナリ データを保持する BLOB フィールドに変更できます。

現在、PHPでフィールドをロードしています。次に、XOR を実行して書き戻します。

ただし、このフィールドはすべてのスクリプトに対してグローバルであり、この方法には次のリスクがあります。

Script X Loads Data0
Script Y Loads Data0
Script X Generates Data1 = Data0 ^ new_data1
Script Y Generates Data2 = Data0 ^ new_data2
Script X writes Data1
Script Y writes Data2 Error: dosen't contain new_data1

これが SQL ステートメントで行われた場合、次のようになります。

UPDATE `my_table` SET `data` = `data` ^ 'new_data1' WHERE `id` = 'field_id'
UPDATE `my_table` SET `data` = `data` ^ 'new_data2' WHERE `id` = 'field_id'

データベースは、上記のエラーを回避することにより、そこでクエリを順次実行します

このデータを格納するために 64 ビット整数を使用する場合、サイズのために 30 個の個別の値に分割する必要があります。このオプションは合理的ではありません。

これを達成するためのデータベースに依存しない方法を知っている人はいますか?

4

1 に答える 1

1

Consider writing a C language User Defined Function (UDF) to do this operation. C UDF's are supported in many databases MySQL, PostgreSQL, Oracle, ....

They are fast and integrate well into SQL, as they are called like any other stored proc. Unfortunately the creation syntax and binding API all differ for each database.

Here is documentation for MySQL

http://dev.mysql.com/doc/refman/5.0/en/udf-compiling.html

and a Codeproject example for MySQL

http://www.codeproject.com/Articles/15643/MySQL-User-Defined-Functions

and PostgreSQL docs http://www.postgresql.org/docs/9.2/static/xfunc-c.html

there many examples of C UDF's in the PostgreSQL source. http://doxygen.postgresql.org/

PostgreSQL takes UDF's one step further and allows to to create C based User Define Types and Operators.

于 2013-05-25T14:48:35.030 に答える