Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2007
    Posts
    130

    Unanswered: how to use a 'view' created by 'create view' in my C/C++ program

    Hello ALL,

    I would like to create and use a view in my C/C++ program. How to create and access the view.

    Can I directly use the following statement in my c/c++ program

    Code:
    create view myview (x, y, ...) as select ......'.,
    but how to declare the variable myview in the C/C++ program?

    Thanks,
    Last edited by cy163; 10-07-08 at 06:41.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    the view is MySQL specific
    its SQL not any thirdparty language like C/C++ or whatever
    so you need to send it to the server as you woudl any other SQL statements

    its a two step process..
    first off create the view (can be done in C++, remember to use drop if exists)
    then use the view as you would in any valid SQL statement
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2007
    Posts
    130
    Quote Originally Posted by healdem
    the view is MySQL specific
    its SQL not any thirdparty language like C/C++ or whatever
    so you need to send it to the server as you woudl any other SQL statements

    its a two step process..
    first off create the view (can be done in C++, remember to use drop if exists)
    then use the view as you would in any valid SQL statement
    healdem, thanks.

    I am new to MySQL. so I am not very clear about your solution.

    When I queried a MySQL database, I had to use the following MySQL C API function
    Code:
    mysql_query("SELECT my_col FROM my_tbl") ;
    in my C/C++ program. I wonder if there is any MySQL C API function to take
    Code:
    "create view viewname (x, y, ....) as select......." as argument.
    Or, I can directly put the above create statement in my C/C++ program.

    Thanks

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    as siad before its a two stage process
    first off you create the view, whetehr tyou do that in C++ or say a query program like MySQL Query browser is up to you.

    havign created the view it then becimes avaialble to you, and any other developer.

    I'd suggest you create the view in MySQL Query Browser.
    you can modify views, by dropping the earlier version and replacing have a look at the doecumentation on views and the drop/create syntax on the MySQL manual

    I don't know C++ but as the create syntax is MySQL SQL thesame function that you sue to SELECT data shoudl also work for view creation. Effectively its exactly the same as other DDL sattements that create or modify tables
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Apr 2007
    Posts
    130
    the solution is
    in C/C++ program,
    mysql_query(create view myview as select ....)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •