简体   繁体   English

如何读取firebird数据库查询结果的大小?

[英]How to read the firebird databases query result size?

I am doing C interface with firebird databases. 我正在使用Firebird数据库进行C接口。 I did some query operations. 我做了一些查询操作。 I would like to know how to read the result size? 我想知道如何读取结果大小?

Below is the code. 下面是代码。 I have created and inserted some values into the table.I would like to read the size of the result. 我已经创建了一些值并将其插入表中。我想读取结果的大小。

#include <stdio.h>
#include "/Library/Frameworks/Firebird.framework/Versions/A/Headers/ibase.h"

static char *createTable="CREATE TABLE newex (Id int)"; //query for creating data table
static char *Insertvalues="INSERT INTO newex values (1)";//doing insertion into the   

//above created table

int SQLOpen(void)
{
    ISC_STATUS          status_vector[20];
    isc_tr_handle       transactionHandle = NULL; //transaction handle
    isc_db_handle       database = SQLGetDatabase();//database handle
    char                logInData [256], *dpb, *p;
    short               bufferLength;
    User_Credentials    credentials;

    sprintf(logInData, "%c%c%c%c%c%c%s%c%c%s",      isc_dpb_version1,
                                                    isc_dpb_num_buffers,
                                                    1,
                                                    90,
                                                    isc_dpb_user_name,
                                                    strlen("SYSDBA"),
                                                    "SYSDBA",
                                                    isc_dpb_password,
                                                    strlen("masterkey"),
                                                    "masterkey"); //passing user //credentials to connect to the database

    bufferLength = strlen(logInData);

    if (isc_attach_database(status_vector, strlen(DATABASE_PATH), DATABASE_PATH, &DatabaseHandle,bufferLength, logInData)) // connecting to database
    {
        SQLTestForErrors(status_vector);
        throw(ConnectionError, "");
    }
return 1;
}
char** SQLQuery(char *query, uint maxRows)
{
    isc_tr_handle   transactionHandle = NULL;
    isc_db_handle   database = SQLGetDatabase();
    short           bufferLength;
    char            dpb_buffer[256], *dpb, *p;
    ISC_STATUS      status_vector[20];


    isc_start_transaction(status_vector, &transactionHandle, 1, &database, 0, NULL);

    if (isc_dsql_execute_immediate(status_vector, &database, &transactionHandle, 0, query, 1, NULL)) //query operations 'create/insert'
    {
        SQLTestForErrors(status_vector);
        throw(QueryError, "");

    }
    isc_commit_transaction(status_vector, &transactionHandle);
   return testString;
}

int main()
{
    //struct Folder_table;
    e4c_using_context(E4C_TRUE)
    {

        SQLOpen();
        SQLQuery(createTable);
        SQLQuery(Insertvalues);
    }

}

You can't in advance: the result set is materialized while you are reading rows (using isc_fetch ): the final number of rows is not known until you have read all rows (at which point you can either have counted it yourself, or query it with an info request). 您无法提前:在读取行时,结果集已实现(使用isc_fetch ):在读取所有行之前,最终行数是未知的(此时您可以自己对它进行计数,也可以查询它与一个信息请求)。

However I notice that you try to use isc_dsql_execute_immediate . 但是我注意到您尝试使用isc_dsql_execute_immediate You can only use isc_dsql_execute_immediate for ddl and for queries that produce one row (you need to prepare and execute for multiple rows). 您只能将isc_dsql_execute_immediate用于ddl和用于产生一行的查询(您需要为多行准备和执行)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM