Exemplo n.º 1
0
int	nnsql_getcolidxbyname( char* col_name )
{
	int	i;

	for( i= 0; nncol_info_tab[i].idx != en_sql_count; i++ )
	{
		if(upper_strneq( col_name, nncol_info_tab[i].name, 16))
			return nncol_info_tab[i].idx;
	}

	return -1;
}
Exemplo n.º 2
0
static int	nndate2date(char* str, date_t* date)
{
	int	i;
	char	buf[4];
	date_t	dt;

	if( STRLEN(str) < STRLEN("yyyy m d") )
		return -1;

	sscanf(str, "%d %s %d", &(dt.day), buf, &(dt.year));

	if( dt.year < 100 && dt.year > 0 )
		dt.year += 1900;

	if( dt.day <= 0 || dt.day > 31 )
		return -1;

	if(i = atoi(buf))
	{
		dt.month = i;

		if( i <= 0 || i > 12 )
			return -1;

		*date = dt;
		date->month = i;

		return 0;
	}

	for(i=0;i<12;i++)
	{
		if( upper_strneq(buf, month_name[i], 3) )
		{
			*date = dt;
			date->month = i+1;

			return 0;
		}
	}

	return -1;
}
Exemplo n.º 3
0
char *
_iodbcdm_getkeyvalinstr (
    char *cnstr,
    int cnlen,
    char *keywd,
    char *value,
    int size)
{
  char token[1024] = {'\0'};
  int flag = 0;

  if (cnstr == NULL || value == NULL
      || keywd == NULL || size < 1)
    {
      return NULL;
    }

  if (cnlen == SQL_NTS)
    {
      cnlen = STRLEN (cnstr);
    }

  if (cnlen <= 0)
    {
      return NULL;
    }

  for (;;)
    {
      cnstr = readtoken (cnstr, token);

      if (*token == '\0')
	{
	  break;
	}

      if (STREQ (token, ";"))
	{
	  flag = 0;
	  continue;
	}

      switch (flag)
	{
	case 0:
	  if (upper_strneq (token, keywd, strlen (keywd)))
	    {
	      flag = 1;
	    }
	  break;

	case 1:
	  if (STREQ (token, "="))
	    {
	      flag = 2;
	    }
	  break;

	case 2:
	  if (size < strlen (token) + 1)
	    {
	      return NULL;
	    }

	  STRNCPY (value, token, size);

	  return value;

	default:
	  break;
	}
    }

  return NULL;
}
Exemplo n.º 4
0
/* 
 *  read odbc init file to resolve the value of specified
 *  key from named or defaulted dsn section 
 */
char *
_iodbcdm_getkeyvalbydsn (
    char *dsn,
    int dsnlen,
    char *keywd,
    char *value,
    int size)
{
  char buf[1024];
  char dsntk[SQL_MAX_DSN_LENGTH + 3] = {'[', '\0'};
  char token[1024];		/* large enough */
  FILE *file;
  char pathbuf[1024];
  char *path;

#define DSN_NOMATCH	0
#define DSN_NAMED	1
#define DSN_DEFAULT	2

  int dsnid = DSN_NOMATCH;
  int defaultdsn = DSN_NOMATCH;

  if (dsn == NULL || *dsn == 0)
    {
      dsn = "default";
      dsnlen = STRLEN (dsn);
    }

  if (dsnlen == SQL_NTS)
    {
      dsnlen = STRLEN (dsn);
    }

  if (dsnlen <= 0 || keywd == NULL || buf == 0 || size <= 0)
    {
      return NULL;
    }

  if (dsnlen > sizeof (dsntk) - 2)
    {
      return NULL;
    }

  value[0] = '\0';

  STRNCAT (dsntk, dsn, dsnlen);
  STRCAT (dsntk, "]");

  dsnlen = dsnlen + 2;

  path = _iodbcdm_getinifile (pathbuf, sizeof (pathbuf));

  if (path == NULL)
    {
      return NULL;
    }

  file = (FILE *) fopen (path, "r");

  if (file == NULL)
    {
      return NULL;
    }

  for (;;)
    {
      char *str;

      str = fgets (buf, sizeof (buf), file);

      if (str == NULL)
	{
	  break;
	}

      if (*str == '[')
	{
	  if (upper_strneq (str, "[default]", STRLEN ("[default]")))
	    {
	      /* we only read first dsn default dsn
	       * section (as well as named dsn).
	       */
	      if (defaultdsn == DSN_NOMATCH)
		{
		  dsnid = DSN_DEFAULT;
		  defaultdsn = DSN_DEFAULT;
		}
	      else
		{
		  dsnid = DSN_NOMATCH;
		}

	      continue;
	    }
	  else if (upper_strneq (str, dsntk, dsnlen))
	    {
	      dsnid = DSN_NAMED;
	    }
	  else
	    {
	      dsnid = DSN_NOMATCH;
	    }

	  continue;
	}
      else if (dsnid == DSN_NOMATCH)
	{
	  continue;
	}

      str = readtoken (str, token);

      if (upper_strneq (keywd, token, STRLEN (keywd)))
	{
	  str = readtoken (str, token);

	  if (!STREQ (token, "="))
	    /* something other than = */
	    {
	      continue;
	    }

	  str = readtoken (str, token);

	  if (STRLEN (token) > size - 1)
	    {
	      break;
	    }

	  STRNCPY (value, token, size);
	  /* copy the value(i.e. next token) to buf */

	  if (dsnid != DSN_DEFAULT)
	    {
	      break;
	    }
	}
    }

  fclose (file);

  return (*value) ? value : NULL;
}
Exemplo n.º 5
0
int	nnsql_odbcdatestr2date(char* str, date_t* date)
/* convert 'yyyy-m-d', 'yyyy-mm-dd' or 'yyyy-mmm-dd' or even 'yyyy/mm/dd'
 * string to date struct */
{
	date_t	dt;
	int	i;

	if( ! str )
	{
		if( date )
			date->day = 0;

		return 0;
	}

	if( STRLEN(str) < STRLEN("yyyy-m-d") )
	{
		if( date )
			date->day = 0;

		return -1;
	}

	dt.day = 0;

	dt.year = atoi(str);	str += 5;

	dt.month = atoi(str);

	if( dt.month < 0 || dt.month > 12 )
	{
		if(date)
			date->day = 0;

		return -1;
	}

	if(! dt.month)			/* jan to dec */
	{
		for(i=0;i<12;i++)
		{
			if( upper_strneq(str, month_name[i], 3) )
			{
				dt.month = i+1;
				break;
			}
		}

		if( ! dt.month )
		{
			if(date)
				date->day = 0;

			return -1;
		}

		str += 4;
	}
	else
	{
		if( *str == '0' || dt.month > 9 )	/* 01 to 12 */
			str += 3;
		else					/* 1 to 9 */
			str += 2;
	}

	dt.day = atoi(str);

	if( dt.day <= 0 || dt.day > 31 )
	{
		if(date)
			date->day = 0;

		return -1;
	}

	if(date)
		*date = dt;

	return 0;
}