Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void checkDBExists(char *dbname, char *createdb){
- char command[100];
- sprintf(command, "psql -l | cut -d '|' -f1 | grep -w %s > .exist_test", dbname);
- system(command);
- FILE *test = fopen(".exist_test", "r");
- if (test != NULL){
- fseek(test, 0, SEEK_END);
- int length = ftell(test);
- if (length == 0){
- sprintf(createdb, "createdb %s 2>/dev/null", dbname);
- system(createdb);
- printf("\nDatabase \"%s\" was created.\n", dbname);
- }
- }
- fclose(test);
- system("rm .exist_test");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement