dbreader クラス : Receive(string)メソッド

説明

指定された列の型名と値を返します。

構文

instance.Receive(string columnName)

引数

クラス名前説明
stringcolumnName列名。

返り値

クラス説明
pair列の型名と値。

サンプルコード

1:

connection cnn = new connection("Data Source=c:\somedirectory\somedatabase.sqlite3;Version=3;");

2:

cnn.Open();

3:

command cmm = new command("select * from sometable where id < 100;", cnn);

4:

dbreader dbr = cmm.Reader(); // Command execution. Returns multi-line results.

5:

while(dbr.Read())

6:

pair value = dbr.Receive("Appropriate column name"); // The return value is a pair class.

7:

string typename = value.First; // The First is typename.

8:

if(typename == "int");

9:

int intValue = value.Second; // The Second is actual value.

10:

elseif(typename == "long");

11:

long longValue = value.Second;

12:

elseif(typename == "real");

13:

real realValue = value.Second;

14:

elseif(typename == "null"); // If the value is database-null, the First is "null".

15:

// If the First is "null", the Second is a dummy class. You have to do nothing to the dummy.

16:

endif;

17:

endwhile

18:

dbr.Release();

19:

cmm.Release();

20:

cnn.Close();

21:

cnn.Release();

注意

返り値のクラス名と実際の値がpairクラスに格納されて返されます。

データベースのカラム型が"INTEGER"で値がintの範囲に収まる場合は、Firstは"int"、Secondはintクラスのインスタンスです。値がintの範囲を超える場合は、Firstは"long"、Secondはlongクラスのインスタンスです。

データベースのカラム型が"REAL"の場合は、Firstは"real"、Secondはrealクラスのインスタンスです。

データベースのカラム型が"TEXT"の場合は、Firstは"string"、Secondはstringクラスのインスタンスです。Get(int)/Get(string)メソッドと違い文字列はダブルクォートで囲まれません。

実際のデータが"NULL"や評価不可能の場合は、データベースのカラム型にかかわらずFirstは"null"、Secondはdummyクラスのインスタンスです。

引数に対応する列が存在しない時は、例外(UnknownException)がスローされます。

参照リンク

無し。

Copyright © Cooker All rights reserved.