Esempio n. 1
0
static int
getAtttypmodEtc(const StatementClass *stmt, int col, int *adtsize_or_longestlen)
{
	int	atttypmod = -1;

	if (NULL != adtsize_or_longestlen)
		*adtsize_or_longestlen = PG_ADT_UNSET;
	if (col >= 0)
	{
		const QResultClass	*res;

		if (res = SC_get_Curres(stmt), NULL != res)
		{
			atttypmod = QR_get_atttypmod(res, col);
			if (NULL != adtsize_or_longestlen)
			{
				if (stmt->catalog_result)
					*adtsize_or_longestlen = QR_get_fieldsize(res, col);
				else
				{
					*adtsize_or_longestlen = QR_get_display_size(res, col);
					if (PG_TYPE_NUMERIC == QR_get_field_type(res, col) &&
					   atttypmod < 0 &&
					   *adtsize_or_longestlen > 0)
					{
						SQLULEN		i;
						size_t		sval, maxscale = 0;
						const char *tval, *sptr;

						for (i = 0; i < res->num_cached_rows; i++)
						{
							tval = QR_get_value_backend_text(res, i, col);
							if (NULL != tval)
							{
								sptr = strchr(tval, '.');
								if (NULL != sptr)
								{
									sval = strlen(tval) - (sptr + 1 - tval);
									if (sval > maxscale)
										maxscale = sval;
								}
							}
						}
						*adtsize_or_longestlen += (int) (maxscale << 16);
					}
				}
			}
		}
	}
	return atttypmod;
}
Esempio n. 2
0
static char *
CC_lookup_cs_new(ConnectionClass *self)
{
	char		*encstr = NULL;
	QResultClass	*res;

	res = CC_send_query(self, "select pg_client_encoding()", NULL, IGNORE_ABORT_ON_CONN | ROLLBACK_ON_ERROR, NULL);
	if (QR_command_maybe_successful(res))
	{
		const char 	*enc = QR_get_value_backend_text(res, 0, 0);

		if (enc)
			encstr = strdup(enc);
	}
	QR_Destructor(res);
	return encstr;
}