PostgreSQL/開発

概要

定義

マクロ

appendStringInfoCharMacro

appendStringInfoCharMacro(str,ch)

 サンプル 

StringInfoData strdata;
initStringInfo(&strdata);
appendStringInfoCharMacro(&strdata, 'A');
elog(NOTICE, "%s", strdata.data);

 参考  appendStringInfoCharMacro - on doxygen.postgresql.org

列挙型

構造体

StringInfoData

StringInfoは,StringInfoDataポインタの別名である

typedef StringInfoData *StringInfo;
番号データ型フィールド説明
1char*data文字列データのポインタ
2intlen文字列の長さ(\0終端)
3intmaxlenバッファ割り当ての最大長
4intcursor文字列バッファのカーソル,makeStringInfoやinitStringInfoで0初期化される。
stringinfo.cルーチンの中で都度更新されるフィールドでない

関数

makeStringInfo

// 引数1:
extern StringInfo makeStringInfo(void);

 サンプル 

StringInfo *strinfo = makeStringInfo();

initStringInfo

// 引数1:StringInfo構造体(StringInfoDataのポインタ)
extern void initStringInfo(StringInfo str);

 サンプル 

StringInfo strinfo = (StringInfo) palloc(sizeof(StringInfoData));
initStringInfo(strinfo);

resetStringInfo

// 引数1:StringInfo構造体(StringInfoDataのポインタ)
extern void resetStringInfo(StringInfo str);

appendStringInfo

// 引数1:StringInfo構造体(StringInfoDataのポインタ)
// 引数2〜:strに追加する文字列のフォーマット指定子と追加する文字列
extern void appendStringInfo(StringInfo str, const char *fmt,...) pg_attribute_printf(2, 3);

 サンプル 

StringInfo strinfo = makeStringInfo();
appendStringInfo(strinfo, "%s", "hoge");
elog(NOTICE, "%s", strinfo->data);

appendStringInfoVA

// 引数1:StringInfo構造体(StringInfoDataのポインタ)
// 引数2〜:strに追加する文字列のフォーマット指定子と追加する文字列
// 引数3:追加する文字列の可変長引数
// 戻り値:=0:書き込み成功,≠0 追加に必要とされる領域サイズ
extern int appendStringInfoVA(StringInfo str, const char *fmt, va_list args) pg_attribute_printf(2, 0);

appendStringInfoString

// 引数1:StringInfo構造体(StringInfoDataのポインタ)
// 引数2:追加する文字列
extern void appendStringInfoString(StringInfo str, const char *s);

appendStringInfoChar

// 引数1:StringInfo構造体(StringInfoDataのポインタ)
// 引数2:追加する文字(シングルバイト)
extern void appendStringInfoChar(StringInfo str, char ch);

appendStringInfoSpaces

// 引数1:StringInfo構造体(StringInfoDataのポインタ)
// 引数2:追加するスペースサイズ
extern void appendStringInfoSpaces(StringInfo str, int count);

appendBinaryStringInfo

// 引数1:引数1:StringInfo構造体(StringInfoDataのポインタ)
// 引数2:追加する文字列
// 引数3:文字列のサイズ
extern void appendBinaryStringInfo(StringInfo str, const char *data, int datalen);

enlargeStringInfo

// 引数1:引数1:StringInfo構造体(StringInfoDataのポインタ)
// 引数2:拡張するサイズ(バイト)
extern void enlargeStringInfo(StringInfo str, int needed);

サンプルプログラム

void stringinfo_sample()
{
    // makeStringInfo()から初期化
    StringInfo strinfo = makeStringInfo();
    appendStringInfo(strinfo, "%s", "hoge");
    elog(NOTICE, "%s", strinfo->data);
    pfree(strinfo->data); // バッファ領域を解放
    pfree(strinfo); // 構造体の領域を解放

    // StringInfoData構造体を使う
    StringInfoData strdata;
    const char* string = "hello world";
    initStringInfo(&strdata); // バッファ領域初期化
    appendBinaryStringInfo(&strdata, string, strlen(string));
    elog(NOTICE, "%s", strdata.data);

    resetStringInfo(&strdata); // リセット,バッファ領域はそのまま
    appendStringInfoChar(&strdata, 'A');
    elog(NOTICE, "%s", strdata.data);
    pfree(strdata.data);
}

参考・関連

コメント



トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
目次
ダブルクリックで閉じるTOP | 閉じる
GO TO TOP