home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------
- *
- * Copyright (c) 1995 Cadre Technologies Inc.
- *
- * This software is furnished under a license and may be used only in
- * accordance with the terms of such license and with the inclusion of
- * the above copyright notice. This software or any other copies thereof
- * may not be provided or otherwise made available to any other person.
- * No title to and ownership of the software is hereby transferred.
- *
- * The information in this software is subject to change without notice
- * and should not be construed as a commitment by Cadre Technologies Inc.
- *
- *---------------------------------------------------------------------------
- *
- * File : @(#)Sybase.cxx 1.2
- * Original date : Mon Dec 4 11:11:19 MET 1995
- * Description : Sybase specific functions
- * uses RogueWave class library
- *
- *---------------------------------------------------------------------------
- */
- static const char SccsId[]="@(#)Sybase.cxx 1.2\t07 Feb 1996 Copyright 1995 Cadre Technologies Inc.";
-
- #define MAX_CHAR_BUF 1024
-
- #include <string.h>
- #include <ctpublic.h>
-
- #ifndef __RWCSTRING_H__
- #include "rw/cstring.h"
- #endif
-
- // taken from example $SYBASE/sample/ctlibrary/exutils.c, ex_display_column()
- //
- RWCString sybConvert(CS_VOID *data, CS_INT dataType, int isStrType, CS_INT dataLength, CS_SMALLINT indicator)
- {
- if (indicator == CS_NULLDATA)
- return "NULL";
-
- CS_CONTEXT *ctx;
- if (cs_ctx_global(CS_VERSION_100, &ctx) != CS_SUCCEED) {
- // error
- //if (dataType == CS_CHAR_TYPE || dataType == CS_VARCHAR_TYPE)
- if (isStrType)
- return "''";
- return "0";
- }
-
- CS_BOOL res;
- cs_will_convert(ctx, dataType, CS_CHAR_TYPE, &res);
- if (res != CS_TRUE) {
- // error
- if (isStrType)
- return "''";
- return "0";
- }
-
- CS_CHAR wbuf[MAX_CHAR_BUF];
- CS_INT olen;
- CS_DATAFMT fmt[2];
- //
- memset(&fmt[0], 0, sizeof(fmt[0]));
- fmt[0].datatype = dataType;
- fmt[0].maxlength = dataLength;
- fmt[0].format = CS_FMT_UNUSED;
- fmt[0].locale = NULL;
- //
- memset(&fmt[1], 0, sizeof(fmt[1]));
- fmt[1].datatype = CS_CHAR_TYPE;
- fmt[1].maxlength = MAX_CHAR_BUF;
- fmt[1].format = CS_FMT_NULLTERM;
- fmt[1].locale = NULL;
-
- if (cs_convert(ctx, &fmt[0], data, &fmt[1], wbuf, &olen) != CS_SUCCEED) {
- // error
- if (isStrType)
- return "''";
- return "0";
- }
-
- if (isStrType) {
- RWCString qStr = "";
- --olen;
- for (int i = 0; i < olen; ++i) {
- if (wbuf[i] == '\'')
- qStr += "'";
- qStr += wbuf[i];
- }
- return "'" + qStr + "'";
- }
-
- return RWCString(wbuf);
- }
-
- char *sybTruncate(char *str)
- {
- for (char *s = str + strlen(str) - 1; s >= str; --s) {
- if (*s != ' ') {
- *(s+1) = '\0';
- return str;
- }
- }
- return str;
- }
-
- #if 0
-
- void *sybNull(CS_INT dataType)
- {
- switch (dataType) {
- case CS_BINARY_TYPE:
- case CS_VARBINARY_TYPE:
- case CS_CHAR_TYPE:
- case CS_VARCHAR_TYPE:
- case CS_BOUNDARY_TYPE:
- case CS_SENSITIVITY_TYPE:
- case CS_TEXT_TYPE:
- case CS_IMAGE_TYPE:
- // empty array/string
- return "";
- case CS_DECIMAL_TYPE:
- case CS_NUMERIC_TYPE:
- // 0.0 (dflt scale and precision)
- break;
- case CS_DATETIME_TYPE:
- // 8 * '\0'
- break;
- case CS_DATETIME4_TYPE:
- // 4 * '\0'
- break;
- case CS_MONEY_TYPE:
- case CS_MONEY4_TYPE:
- // $0.0
- break;
- default:
- // 0
- break;
- }
- }
-
- #endif /* 0 */
-