libtabula

Check-in [f2cdede2a0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merged trunk changes in
Timelines: family | ancestors | descendants | both | mysql-type-info
Files: files | file ages | folders
SHA1: f2cdede2a059f926adf21f4572394630cbd3e8f7
User & Date: tangent 2015-08-14 03:55:33
Context
2015-08-14
05:40
Merged trunk changes check-in: 5f36ef6682 user: tangent tags: mysql-type-info
03:55
Merged trunk changes in check-in: f2cdede2a0 user: tangent tags: mysql-type-info
03:55
Dropped the versioned crnl-glob Fossil setting. All *.md and *.txt are now LF-only. check-in: c37cba89a5 user: tangent tags: trunk
03:43
Fixed an operator precedence complaint in the new field type matching code noticed by Clang. check-in: f8610afda3 user: tangent tags: mysql-type-info
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Deleted .fossil-settings/crnl-glob.

1
*.md, *.txt
<


Changes to examples/cgi_jpeg.cpp.

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45





46
47
48
49
50
51
52
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 USA
***********************************************************************/

#include "cmdline.h"
#include "images.h"

#define CRLF			"\r\n"
#define CRLF2			"\r\n\r\n"

int
main(int argc, char* argv[])
{
	// Get database access parameters from command line if present, else
	// use hard-coded values for true CGI case.
	libtabula::examples::CommandLine cmdline(argc, argv, "root",
			"nunyabinness");
	if (!cmdline) {
		return 1;
	}






	// Parse CGI query string environment variable to get image ID
	unsigned int img_id = 0;
	char* cgi_query = getenv("QUERY_STRING");
	if (cgi_query) {
		if ((strlen(cgi_query) < 4) || memcmp(cgi_query, "id=", 3)) {
			std::cout << "Content-type: text/plain" << std::endl << std::endl;
................................................................................
				cmdline.server(), cmdline.user(), cmdline.pass());
		libtabula::Query query = con.query();
		query << "SELECT * FROM images WHERE id = " << img_id;
		libtabula::StoreQueryResult res = query.store();
		if (res && res.num_rows()) {
			images img = res[0];
			if (img.data.is_null) {
				std::cout << "Content-type: text/plain" << CRLF2;
				std::cout << "No image content!" << CRLF;
			}
			else {
				std::cout << "X-Image-Id: " << img_id << CRLF; // for debugging
				std::cout << "Content-type: image/jpeg" << CRLF;
				std::cout << "Content-length: " <<
						img.data.data.length() << CRLF2;
				std::cout << img.data;
			}
		}
		else {
			std::cout << "Content-type: text/plain" << CRLF2;
			std::cout << "ERROR: No image with ID " << img_id << CRLF;
		}
	}
	catch (const libtabula::BadQuery& er) {
		// Handle any query errors
		std::cout << "Content-type: text/plain" << CRLF2;
		std::cout << "QUERY ERROR: " << er.what() << CRLF;
		return 1;
	}
	catch (const libtabula::Exception& er) {
		// Catch-all for any other libtabula exceptions
		std::cout << "Content-type: text/plain" << CRLF2;
		std::cout << "GENERAL ERROR: " << er.what() << CRLF;
		return 1;
	}

	return 0;
}







<
<
<










>
>
>
>
>







 







|
|


|
|

|




|
|




|
|




|
|





26
27
28
29
30
31
32



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
..
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 USA
***********************************************************************/

#include "cmdline.h"
#include "images.h"




int
main(int argc, char* argv[])
{
	// Get database access parameters from command line if present, else
	// use hard-coded values for true CGI case.
	libtabula::examples::CommandLine cmdline(argc, argv, "root",
			"nunyabinness");
	if (!cmdline) {
		return 1;
	}

	// Define line ending style used in output, varying depending on
	// whether the output is CGI/HTTP or the bmark.txt file for dtest.
	const char* eol1 = cmdline.dtest_mode() ? "\n" : "\r\n";
	const char* eol2 = cmdline.dtest_mode() ? "\n" : "\r\n\r\n";

	// Parse CGI query string environment variable to get image ID
	unsigned int img_id = 0;
	char* cgi_query = getenv("QUERY_STRING");
	if (cgi_query) {
		if ((strlen(cgi_query) < 4) || memcmp(cgi_query, "id=", 3)) {
			std::cout << "Content-type: text/plain" << std::endl << std::endl;
................................................................................
				cmdline.server(), cmdline.user(), cmdline.pass());
		libtabula::Query query = con.query();
		query << "SELECT * FROM images WHERE id = " << img_id;
		libtabula::StoreQueryResult res = query.store();
		if (res && res.num_rows()) {
			images img = res[0];
			if (img.data.is_null) {
				std::cout << "Content-type: text/plain" << eol2;
				std::cout << "No image content!" << eol1;
			}
			else {
				std::cout << "X-Image-Id: " << img_id << eol1; // for debugging
				std::cout << "Content-type: image/jpeg" << eol1;
				std::cout << "Content-length: " <<
						img.data.data.length() << eol2;
				std::cout << img.data;
			}
		}
		else {
			std::cout << "Content-type: text/plain" << eol2;
			std::cout << "ERROR: No image with ID " << img_id << eol1;
		}
	}
	catch (const libtabula::BadQuery& er) {
		// Handle any query errors
		std::cout << "Content-type: text/plain" << eol2;
		std::cout << "QUERY ERROR: " << er.what() << eol1;
		return 1;
	}
	catch (const libtabula::Exception& er) {
		// Catch-all for any other libtabula exceptions
		std::cout << "Content-type: text/plain" << eol2;
		std::cout << "GENERAL ERROR: " << er.what() << eol1;
		return 1;
	}

	return 0;
}