Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sqlca.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <sys/time.h>
- #include <unistd.h>
- #include <sqltypes.h>
- void error_func(char *message, int code) {
- printf("Error code: %d\nMessaeg: \n", code, message);
- printf("Error hu2: %s\n", sqlca.sqlerrm.sqlerrmc);
- }
- int main() {
- /****************************************\
- |* Объявляем переменные для работы с БД *|
- \****************************************/
- EXEC SQL begin declare section;
- int buf;
- EXEC SQL end declare section;
- /*********************\
- |* Подключаемся к БД *|
- \*********************/
- exec sql connect to students@fpm2.ami.nstu.ru user "pmi-b6103" using "juIppOw3";
- if(sqlca.sqlcode!=0) {
- printf("Authentication failed\n");
- return 1;
- }
- /*******************************************************\
- |* Устанавливаем схему, в которой будем искать таблицу *|
- \*******************************************************/
- EXEC SQL set search_path to pmib6103;
- if(sqlca.sqlcode!=0) {
- printf("Error\n");
- return 2;
- }
- /**********************\
- |* Выполнение запроса *|
- \**********************/
- exec sql begin work;
- exec sql SELECT COUNT(DISTINCT spj.n_post) into :buf
- FROM spj
- JOIN j ON j.n_izd = spj.n_izd
- WHERE j.town IN (SELECT p.town
- FROM p
- WHERE p.cvet = 'Красный');
- exec sql commit work;
- if(sqlca.sqlcode != 0) {
- error_func("select", sqlca.sqlcode);
- exec sql rollback;
- } else {
- printf("Количество поставщиков: %d\n", buf);
- exec sql commit;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement