Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u8piu-00CKbq-1G for pgsql-general@arkaria.postgresql.org; Sun, 27 Apr 2025 00:18:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u8pis-007ynB-AW for pgsql-general@arkaria.postgresql.org; Sun, 27 Apr 2025 00:18:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u8pir-007yn3-Ve for pgsql-general@lists.postgresql.org; Sun, 27 Apr 2025 00:18:18 +0000 Received: from mail-yw1-x1133.google.com ([2607:f8b0:4864:20::1133]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u8pip-002FVQ-2l for pgsql-general@lists.postgresql.org; Sun, 27 Apr 2025 00:18:18 +0000 Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-7082e46880eso32044067b3.1 for ; Sat, 26 Apr 2025 17:18:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745713094; x=1746317894; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=TPEHnXzzeRHI6v8HnJnS6wpA9zSRHa32ChrsMVTaErk=; b=lJMwpwymBAyhcZSPd0n00XstBtKz+Gq687rIuE0MEdVig3c4MYfiXiZrJaUn02Rgbd FxAsDNfSG03sPe9FVHCaLfNiBE6UUi1GtY4/77fXwAD1LIqQ/PY7AKgE28oZvP04bxGr lyDsouZN56CrZplkSADugLSHSMTBc+OS3wGn+dDvryMO8tpCJSvoTa2jn2pczUuXww7D Id5JreVwGxJgia26DvFWL02mkDV5jBUavBBcsTlq+Ehdfk8IYVFmMHWm19ZEnGhNqSD5 7duB2z7YBUkFh4KM3hVCAdJrvzP9ZIl+EnuywJh1wiVvapDSFhkmgWWuQSNpsoZBZ0X5 nlTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745713094; x=1746317894; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TPEHnXzzeRHI6v8HnJnS6wpA9zSRHa32ChrsMVTaErk=; b=JEV1AS4zKESSKB5n2SfXfchZ3WfAZAJUoXx0e55x874cqK6aqXti1AoP2111Pdp9VL U9/JE/ZOUKkIhUoFyjLV73UZ72sCWJHcOhkiB5mIjiTVWdiFbO/AwPqssib1l3juno1y nORT2BQAoq7QGPswQqixRgoA51Zz6SoZKqnjqL/aGsN7BbEQdrT6fZuybbgkComOUXlA IFO58GnmIFdss8j6hVnoS831XFTifGSLFSMDvbkIa2bAampp77obawtlIyuSc0wpdjz4 K0/XxLa8h1/3/2JAp3I3PGsJ10NBUpbx0yH3A0FISolTSZe0RgThc5mc2ho+y0QTQrmG dCsg== X-Gm-Message-State: AOJu0Yz944xjrCw5FUIGQdc0J+dpWAovU6QXxZeZuIfUFInLVYyCddf+ eFeq4f9Rfqsz0Rve2Hk5svXdhRWN5/8rBXhp9P8Z+YigrMf7J3dFeKp23hCpjsgpusGB35e9a0q KkSka7aKlqrSOfbm6uab6BAkUdm5PJkZ6xwg= X-Gm-Gg: ASbGnctw5AmjZPKylmzcnrre4u25lGXfMFogdRwpLC8b2Jid6Q+cEyEeUXEoLVaC90A RSGbK0VQz+b+olZ7Lc0jWSLZUkeI59FPyhRj6lvzromszxgBqhIwWEIBaPZf3R0T5BTjo2o4I1g Ny+URn9gm4wgpT3w3UyIKLmropptXeCcwxgxi4tj8Iwr7qqiBUa2WhicOZRD7RXYrfww== X-Google-Smtp-Source: AGHT+IH/5rf+aVjCI3ZV5bGJl+WLNDJ5eTWUVAIicCJZ6afFYl3bWOIkq9kQLivadTJEW0EHkcRUfqb/cbRixwE9Cmg= X-Received: by 2002:a05:690c:6904:b0:708:139e:4e03 with SMTP id 00721157ae682-708540fa224mr111083157b3.16.1745713094210; Sat, 26 Apr 2025 17:18:14 -0700 (PDT) MIME-Version: 1.0 From: Igor Korot Date: Sat, 26 Apr 2025 19:18:03 -0500 X-Gm-Features: ATxdqUFdbPmi3s5IYvyheKs4_M17BjwjLDax1e_CWKMwGU3XQr4tjSqqQAsCl_M Message-ID: Subject: How to get the data from the query To: "pgsql-generallists.postgresql.org" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, ALL, [code] std::wstring query2 = L"SELECT DISTINCT column_name, data_type, character_maximum_length, character_octet_length, numeric_precision, numeric_precision_radix, numeric_scale, is_nullable, column_default, CASE WHEN column_name IN (SELECT ccu.column_name FROM information_schema.constraint_column_usage ccu, information_schema.table_constraints tc WHERE ccu.constraint_name = tc.constraint_name AND tc.constraint_type = 'PRIMARY KEY' AND ccu.table_name = 'leagues') THEN 'YES' ELSE 'NO' END AS is_pk, ordinal_position FROM information_schema.columns col, information_schema.table_constraints tc WHERE tc.table_schema = col.table_schema AND tc.table_name = col.table_name AND col.table_schema = $1 AND col.table_name = $2 ORDER BY ordinal_position;"; res2 = PQprepare( m_db, "get_columns", m_pimpl->m_myconv.to_bytes( query2.c_str() ).c_str(), 2, NULL ); if( PQresultStatus( res2 ) != PGRES_COMMAND_OK ) { std::wstring err = m_pimpl->m_myconv.from_bytes( PQerrorMessage( m_db ) ); errorMsg.push_back( L"Error executing query: " + err ); PQclear( res2 ); result = 1; } else { PQclear( res2 ); ...... res2 = PQexecPrepared( m_db, "get_columns", 2, values1, length1, formats1, 1 ); status = PQresultStatus( res2 ); if( status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK ) { std::wstring err = m_pimpl->m_myconv.from_bytes( PQerrorMessage( m_db ) ); errorMsg.push_back( L"Error executing query: " + err ); PQclear( res2 ); fields.erase( fields.begin(), fields.end() ); foreign_keys.erase( foreign_keys.begin(), foreign_keys.end() ); result = 1; } else if( status == PGRES_TUPLES_OK ) { int numFields = 0; for( int j = 0; j < PQntuples( res2 ); j++ ) { int size, precision; bool autoinc = false; const char *field_name = PQgetvalue( res2, j, 0 ); fieldName = m_pimpl->m_myconv.from_bytes( field_name ); fieldType = m_pimpl->m_myconv.from_bytes( PQgetvalue( res2, j, 1 ) ); char *char_length = PQgetvalue( res2, j, 2 ); char *numeric_length = PQgetvalue( res2, j, 4 ); char *numeric_scale = PQgetvalue( res2, j, 6 ); fieldDefaultValue = m_pimpl->m_myconv.from_bytes( PQgetvalue( res2, j, 8 ) ); fieldIsNull = !strcmp( PQgetvalue( res2, j, 7 ), "YES" ) ? 1 : 0; fieldPK = !strcmp( PQgetvalue( res2, j, 9 ), "YES" ) ? 1 : 0; if( *char_length == '0' ) { size = atoi( numeric_length ); precision = atoi( numeric_scale ); } else { size = atoi( char_length ); precision = 0; } if( fieldType == L"serial" || fieldType == L"bigserial" ) autoinc = true; [/code] I'm able to get field name and field type, but the size comes out "" (empty) . WHat am I doing wrong? Thank you.