• vc6操作PostgreSQL增加错误检测和现实链接属性


    老外做东西真的很细腻哈,一个新手读读document 竟然如此的顺利

    看来比想象的多多了。


    如果远程访问的化,需要配置 conf文件,以后在看去吧,暂时先用127.0.0.1 代替

    上代码

    // pgDemo.cpp : Defines the entry point for the console application.
    //


    #include "stdafx.h"


    #include "libpq-fe.h"


    static void show_connection_attributes( const PGconn * conn );
    static const char * check( const char * value );


    int main(int argc, char* argv[])
    {
      PGconn * connection; 
      /** 顺带解释下,链接字符串的构成
      Table 8.2. Connection Attributes Connect-String Keyword
      Environment Variable Example
      user PGUSER user=korry
      password PGPASSWORD password=cows
      dbname PGDATABASE dbname=accounting 
      host PGHOST host=jersey
      hostaddr PGHOSTADDR hostaddr=127.0.0.1
      service PGSERVICE service=accounting 
      port PGPORT port=5432 
      **/
      
      // 用下面这个是因为不需要SSL的支持,加上IP就需要了
      // 注意大小写敏感
      connection = PQconnectdb( "dbname=mydb user=Eagle password=123456 hostaddr=127.0.0.1");  
           
      if ( PQstatus(connection) != CONNECTION_OK )
      {
      printf("%s \n", PQerrorMessage(connection) );
      }
      else
      {
      printf("connect is ok \n");
      }
      
      show_connection_attributes( connection );


      PQfinish( connection);
      
      return 0;
    }


    static const char * check( const char * value )
    {
    if( value )
    return( value );
    else
    return( "(null)" );
    }


    static void show_connection_attributes( const PGconn * c )
    {
    printf( "dbname   = %s\n", check( PQdb( c )));
    printf( "user     = %s\n", check( PQuser( c )));
    printf( "password = %s\n", check( PQpass( c )));
    printf( "host     = %s\n", check( PQhost( c )));
    printf( "port     = %s\n", check( PQport( c )));
    printf( "tty      = %s\n", check( PQtty( c )));
    printf( "options  = %s\n", check( PQoptions( c )));
    }


    程序运行截图:


  • 相关阅读:
    数据库信息 (表名 行数 堆 集群 非聚集)的查询
    jquerygalleryview2.0 漂亮多样化的图片特效(多项自定义)
    枚举 EnumDescription 位运算 权限 sql c#
    vs2010缓存类
    透明遮罩层
    app_offline.htm的作用
    XmlToJSON(c#)
    jquery性能最佳实践
    .net面试问答(大汇总)
    apk反编译
  • 原文地址:https://www.cnblogs.com/eaglezzb/p/4176541.html
Copyright © 2020-2023  润新知