/***************************************************************** * test-bytea.c the executed module contains test of bytea's type * as well as it's used as example. As a result of * its executing is added entry to the sql-table * called "images". * * Copyright (C) 2009 Andrey Y. Rjavskov(aka rjaan) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * *****************************************************************/ #include "test-common.h" #include "test-config.h" int main( int argc, char** argv ) { PngFileMark mark; PGconn* testdb; unsigned char *oct_array = NULL; size_t nbytes; int ret_val = EXIT_SUCCESS; if( argc != 2 ) { char *progname = get_progname_from ( argv[0] ); printf( "Usage: %s \n", progname ); free(progname); return EXIT_FAILURE; } if ( ( mark = is_file_png ( argv[1] ) ) != FILE_IS_PNG ) { fprintf (stderr,"file \'%s\' %s\n", argv[1], (mark == FILE_IS_NOT_PNG ? FILE_IS_NOT_PNG_MSG : mark == ERROR_OPEN_PNGFILE? ERROR_OPEN_PNGFILE_MSG : mark == ERROR_READ_PNGFILE ? ERROR_READ_PNGFILE_MSG : UNKNOWN_ERROR_MSG) ); fflush (stderr); return EXIT_FAILURE; } testdb = upg_connect_db ( BT_DBHOST, BT_DBPORT, BT_DBNAME, NULL, NULL ); if ( !testdb ) { return EXIT_FAILURE; } oct_array = get_escape_bytea_array ( argv[1], &nbytes ); if ( !oct_array ) { return EXIT_FAILURE; } if ( nbytes >= 1024 ) { ret_val = bytea_entry_add ( testdb, (const char*)oct_array, "%s, %d Kbytes", argv[1], nbytes/1024 ); }else { ret_val = bytea_entry_add ( testdb, (const char*)oct_array, "%s, %d bytes", argv[1], nbytes ); } if ( ret_val == EXIT_SUCCESS ) { printf ( "File \'%s\' added!\n", argv[1] ); } if ( oct_array ) free( oct_array ); upg_disconnect_db ( testdb ); return ret_val; } /*eof*/