⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 new_rec.c

📁 解压后将扩展名改为.C就可以了.实现在SQL里连接SQL.
💻 C
字号:
/* This sample program shows how to create a database record. */

/* define PURE_SQL to use a SQL INSERT INTO statement instead of   */
/* DBCreateRecord and DBPutRecord.                                 */
#undef PURE_SQL
#include "cvi_db.h"
#include <ansi_c.h>
#include <userint.h>

void ShowError()
{
    MessagePopup("Database Error",DBErrorMessage());
}


void main()
{
    int hdbc = 0;       /* Handle to database connection    */
    int hmap = 0;       /* Handle to map                    */
    int hstmt = 0;      /* Handle to SQL statement          */
    char uutNum[11];    /* Buffer for uut serial number     */
    int uutStat;        /* Status variable for uut number   */
    double meas1;       /* Variable for test measurement 1  */
    int meas1Stat;      /* Fetch status  for measurement 1  */
    double meas2;       /* Variable for test measurement 2  */
    int meas2Stat;      /* Fetch tatus for measurement 2    */
    int resCode;        /* Result code                      */

    /* Connect to data source (in this case dBase files) */
    hdbc = DBConnect ("DSN=CVI SQL 2.0 Samples");
    if (hdbc <= 0) {ShowError(); goto Error;}

#ifdef PURE_SQL
    resCode = DBImmediateSQL(hdbc, "INSERT INTO TESTRES (UUT_NUM, MEAS1, MEAS2) \
                VALUES ('2860B567',0.7,1.1)");
#else

    /* begin map for constructed SQL statement */
    hmap = DBBeginMap (hdbc);
    if (hmap <= 0) {ShowError(); goto Error;}

    /* specify the columns to be selected and the variables where column */
    /* values will be placed.                                            */
    resCode = DBMapColumnToChar (hmap, "UUT_NUM", 11, uutNum, &uutStat, "");
    if (resCode != DB_SUCCESS) {ShowError(); goto Error;}
    resCode = DBMapColumnToDouble (hmap, "MEAS1", &meas1, &meas1Stat);
    if (resCode != DB_SUCCESS) {ShowError(); goto Error;}
    resCode = DBMapColumnToDouble (hmap, "MEAS2", &meas2, &meas2Stat);
    if (resCode != DB_SUCCESS) {ShowError(); goto Error;}

    /* Activate the map for table testres.  (construct a SQL Select     */
    /* statement, execute the statement, bind the selected columns to   */
    /* the previously specified variables.)                             */
    hstmt = DBActivateMap (hmap, "testres");
    if (hstmt <= 0) {ShowError(); goto Error;}

    /* Create the new record */
    resCode = DBCreateRecord (hstmt);
    if (resCode != DB_SUCCESS) {ShowError(); goto Error;}

    /* Put values into the bound variables */
    strcpy(uutNum, "2860B567");
    meas1 = 0.7;
    meas2 = 1.1;

    /* Insert the record into the database */
    resCode = DBPutRecord (hstmt);
    if (resCode != DB_SUCCESS) {ShowError(); goto Error;}

    resCode = DBDeactivateMap (hmap);
    if (resCode != DB_SUCCESS) {ShowError(); goto Error;}
#endif
    resCode = DBDisconnect (hdbc);
    if (resCode != DB_SUCCESS) {ShowError(); goto Error;}
    MessagePopup ("Create Record Sample",
                  "Successfully created record for UUT_NUM 2860B567");
    return;
Error:
    return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -