Exemplo n.º 1
1
/*
 * css_accept() - accept of a request from a client
 *   return:
 *   sockfd(in):
 */
static SOCKET
css_accept (SOCKET sockfd)
{
  struct sockaddr_in tcp_cli_addr;
  SOCKET newsockfd;
  int clilen, error;

  while (true)
    {
      clilen = sizeof (tcp_cli_addr);
      newsockfd = accept (sockfd, (struct sockaddr *) &tcp_cli_addr, &clilen);

      if (IS_INVALID_SOCKET (newsockfd))
	{
	  error = WSAGetLastError ();
	  if (error == WSAEINTR)
	    {
	      continue;
	    }

	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ERR_CSS_WINTCP_ACCEPT_ERROR, 1, error);
	  return INVALID_SOCKET;
	}

      break;
    }

  return newsockfd;
}
Exemplo n.º 2
0
/*
 * logwr_fetch_header_page -
 *
 * return:
 *   log_pgptr(out):
 * Note:
 */
static int
logwr_fetch_header_page (LOG_PAGE * log_pgptr)
{
  PAGEID pageid;
  PAGEID phy_pageid;

  assert (log_pgptr != NULL);

  /*
   * Page is contained in the active log.
   * Find the corresponding physical page and read the page form disk.
   */
  pageid = LOGPB_HEADER_PAGE_ID;
  phy_pageid = logwr_to_physical_pageid (pageid);

  if (fileio_read (NULL, logwr_Gl.append_vdes, log_pgptr, phy_pageid,
		   LOG_PAGESIZE) == NULL)
    {
      er_set (ER_FATAL_ERROR_SEVERITY, ARG_FILE_LINE,
	      ER_LOG_READ, 3, pageid, phy_pageid, logwr_Gl.active_name);
      return ER_LOG_READ;
    }
  else
    {
      if (log_pgptr->hdr.logical_pageid != pageid)
	{
	  er_set (ER_FATAL_ERROR_SEVERITY, ARG_FILE_LINE,
		  ER_LOG_PAGE_CORRUPTED, 1, pageid);
	  return ER_LOG_PAGE_CORRUPTED;
	}
    }

  return NO_ERROR;
}
Exemplo n.º 3
0
/*
 * pt_report_to_ersys_with_statement () - report query compilation error by
 *                                        setting global ER state
 *   return:
 *   parser(in): handle to parser used to process the query
 *   error_type(in): syntax, semantic, or execution
 *   statement(in): statement tree
 */
void
pt_report_to_ersys_with_statement (PARSER_CONTEXT * parser, const PT_ERROR_TYPE error_type, PT_NODE * statement)
{
  PT_NODE *error_node;
  char buf[1000];
  char *stmt_string = NULL;
  int err;

  if (parser == NULL)
    {
      return;
    }

  error_node = parser->error_msgs;
  if (statement)
    {
      PT_NODE_PRINT_TO_ALIAS (parser, statement, PT_CONVERT_RANGE | PT_SHORT_PRINT);
      stmt_string = (char *) statement->alias_print;
    }
  if (stmt_string == NULL)
    {
      stmt_string = (char *) "";
    }

  if (error_node && error_node->node_type == PT_ZZ_ERROR_MSG)
    {
#if 0				/* TODO */
      assert (er_errid () != NO_ERROR);
#endif
      err = er_errid ();
      if (!ER_IS_LOCK_TIMEOUT_ERROR (err) && !ER_IS_SERVER_DOWN_ERROR (err))
	{
	  switch (error_type)
	    {
	    case PT_SYNTAX:
	      er_set (ER_SYNTAX_ERROR_SEVERITY, ARG_FILE_LINE, ER_PT_SYNTAX, 2,
		      error_node->info.error_msg.error_message, stmt_string);
	      break;
	    case PT_SEMANTIC:
	    default:
	      er_set (ER_SYNTAX_ERROR_SEVERITY, ARG_FILE_LINE, ER_PT_SEMANTIC, 2,
		      error_node->info.error_msg.error_message, stmt_string);
	      break;
	    case PT_EXECUTION:
	      er_set (ER_SYNTAX_ERROR_SEVERITY, ARG_FILE_LINE, ER_PT_EXECUTE, 2,
		      error_node->info.error_msg.error_message, stmt_string);
	      break;
	    }
	}
      return;
    }

  /* a system error reporting error messages */
  sprintf (buf, "Internal error- reporting %s error.",
	   (error_type == PT_SYNTAX ? "syntax" : (error_type == PT_SEMANTIC ? "semantic" : "execution")));

  er_set (ER_SYNTAX_ERROR_SEVERITY, ARG_FILE_LINE, ER_PT_EXECUTE, 2, buf, stmt_string);
}				/* pt_report_to_ersys_with_statement() */
Exemplo n.º 4
0
/*
 * es_init - initialization action of External Storage module
 *
 * return: error code
 */
int
es_init (const char *uri)
{
  int ret;
  ES_TYPE es_type;

  assert (uri != NULL);

  es_type = es_get_type (uri);
  if (es_type == ES_NONE)
    {
      ret = ER_ES_INVALID_PATH;
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ret, 1, uri);
      return ret;
    }

  if (es_initialized_type == es_type)
    {
      return NO_ERROR;
    }
  else
    {
      es_final ();
    }

  es_initialized_type = es_type;
  if (es_initialized_type == ES_OWFS)
    {
#if defined(WINDOWS)
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ES_GENERAL, 2, "OwFS", "not supported");
      ret = ER_ES_GENERAL;
#else /* WINDOWS */
      ret = es_owfs_init (ES_POSIX_PATH_POS (uri));
#endif /* !WINDOWS */
    }
  else if (es_initialized_type == ES_POSIX)
    {
      ret = es_posix_init (ES_POSIX_PATH_POS (uri));
      if (ret == ER_ES_GENERAL)
	{
	  /* 
	   * If es_posix_init() failed (eg.failed to open base dir), 
	   * ignore the error in order to start server normally. 
	   */
	  ret = NO_ERROR;
	}
    }
  else
    {
      ret = ER_ES_INVALID_PATH;
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ret, 1, uri);
    }

  srand (time (NULL));

  return ret;
}
Exemplo n.º 5
0
/*
 * init_gcrypt() -- Initialize libgcrypt
 *   return: Success, returns NO_ERROR.
 */
static int
init_gcrypt (void)
{
  /* if gcrypt init success, it doesn't return GPG_ERR_NO_ERROR. It's kind of weird! */
#define GCRYPT_INIT_SUCCESS gcry_error(GPG_ERR_GENERAL)

  gcry_error_t i_gcrypt_err;
  if (gcrypt_initialized == 0)
    {
#if defined(SERVER_MODE)
      pthread_mutex_lock (&gcrypt_init_mutex);

      if (gcrypt_initialized == 1)
	{
	  /* It means other concurrent thread has initialized gcrypt when the thread blocked by
	   * pthread_mutex_lock(&gcrypt_init_mutex). */
	  pthread_mutex_unlock (&gcrypt_init_mutex);
	  return NO_ERROR;
	}

      i_gcrypt_err = gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
      if (i_gcrypt_err != GPG_ERR_NO_ERROR)
	{
	  pthread_mutex_unlock (&gcrypt_init_mutex);
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ENCRYPTION_LIB_FAILED, 1,
		  crypt_lib_fail_info[CRYPT_LIB_INIT_ERR]);
	  return ER_ENCRYPTION_LIB_FAILED;
	}
#endif
      gcry_check_version (NULL);

      /* allocate secure memory */
      gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN);
      gcry_control (GCRYCTL_INIT_SECMEM, GCRYPT_SECURE_MEMORY_LEN, 0);
      gcry_control (GCRYCTL_RESUME_SECMEM_WARN);

      gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);

      i_gcrypt_err = gcry_control (GCRYCTL_INITIALIZATION_FINISHED_P);
      if (i_gcrypt_err != GCRYPT_INIT_SUCCESS)
	{
#if defined(SERVER_MODE)
	  pthread_mutex_unlock (&gcrypt_init_mutex);
#endif
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ENCRYPTION_LIB_FAILED, 1,
		  crypt_lib_fail_info[CRYPT_LIB_INIT_ERR]);
	  return ER_ENCRYPTION_LIB_FAILED;
	}
      gcrypt_initialized = (i_gcrypt_err == GCRYPT_INIT_SUCCESS) ? 1 : 0;
#if defined(SERVER_MODE)
      pthread_mutex_unlock (&gcrypt_init_mutex);
#endif
      return NO_ERROR;
    }
  return NO_ERROR;
}
Exemplo n.º 6
0
/*
 * event_file_open - Open event log file
 *   return: FILE *
 *   path(in): file path
 */
static FILE *
event_file_open (const char *path)
{
  FILE *fp;
  char dir[PATH_MAX], *tpath;

  assert (path != NULL);

  tpath = strdup (path);
  if (tpath == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, (size_t) strlen (path));
      return NULL;
    }

  while (1)
    {
      if (cub_dirname_r (tpath, dir, PATH_MAX) > 0 && access (dir, F_OK) < 0)
	{
	  if (mkdir (dir, 0777) < 0 && errno == ENOENT)
	    {
	      free_and_init (tpath);

	      tpath = strdup (dir);
	      if (tpath == NULL)
		{
		  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, (size_t) strlen (dir));
		  return NULL;
		}

	      continue;
	    }
	}

      break;
    }

  free_and_init (tpath);

  fp = fopen (path, "r+");
  if (fp != NULL)
    {
      fseek (fp, 0, SEEK_END);
      if (ftell (fp) > prm_get_integer_value (PRM_ID_ER_LOG_SIZE))
	{
	  fp = event_file_backup (fp, path);
	}
    }
  else
    {
      fp = fopen (path, "w");
    }

  return fp;
}
Exemplo n.º 7
0
/*
 * es_rename_file - rename a locator according to the metaname
 *
 * return: error code
 * in_uri(in):
 * metapath(in) : meta name combined with in_uri
 * out_uri(out):
 */
int
es_rename_file (const char *in_uri, const char *metaname, char *out_uri)
{
  int ret;
  ES_TYPE es_type;

  assert (in_uri != NULL);
  assert (out_uri != NULL);
  assert (metaname != NULL);

  if (es_initialized_type == ES_NONE)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ES_NO_LOB_PATH, 0);
      return ER_ES_NO_LOB_PATH;
    }

  es_type = es_get_type (in_uri);
  if (es_type != es_initialized_type)
    {
      /* copy file operation is allowed only between same types */
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ES_COPY_TO_DIFFERENT_TYPE, 2, es_get_type_string (es_type),
	      es_get_type_string (es_initialized_type));
      return ER_ES_COPY_TO_DIFFERENT_TYPE;
    }

  if (es_type == ES_OWFS)
    {
#if defined(WINDOWS)
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ES_GENERAL, 2, "OwFS", "not supported");
      ret = ER_ES_GENERAL;
#else /* WINDOWS */
      strncpy (out_uri, ES_OWFS_PATH_PREFIX, sizeof (ES_OWFS_PATH_PREFIX));
      ret = es_owfs_rename_file (ES_OWFS_PATH_POS (in_uri), metaname, ES_OWFS_PATH_POS (out_uri));
      er_log_debug (ARG_FILE_LINE, "es_copy_file: es_owfs_copy_file(%s) -> %s: %d\n", in_uri, out_uri, ret);
#endif /* !WINDOWS */
    }
  else if (es_type == ES_POSIX)
    {
      strncpy (out_uri, ES_POSIX_PATH_PREFIX, sizeof (ES_POSIX_PATH_PREFIX));
#if defined (CS_MODE)
      ret = es_posix_rename_file (ES_POSIX_PATH_POS (in_uri), metaname, ES_POSIX_PATH_POS (out_uri));
      er_log_debug (ARG_FILE_LINE, "es_copy_file: es_posix_copy_file(%s) -> %s: %d\n", in_uri, out_uri, ret);
#else /* CS_MODE */
      ret = xes_posix_rename_file (ES_POSIX_PATH_POS (in_uri), metaname, ES_POSIX_PATH_POS (out_uri));
      er_log_debug (ARG_FILE_LINE, "es_copy_file: xes_posix_copy_file(%s) -> %s: %d\n", in_uri, out_uri, ret);
#endif /* SERVER_MODE || SA_MODE */
    }
  else
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ES_INVALID_PATH, 1, in_uri);
      return ER_ES_INVALID_PATH;
    }

  return ret;
}
Exemplo n.º 8
0
/*
 * es_read_file -
 *
 * return:
 * uri(in)
 * buf(out)
 * count(in)
 * offset(in)
 */
ssize_t
es_read_file (const char *uri, void *buf, size_t count, off_t offset)
{
  ssize_t ret;
  ES_TYPE es_type;

  assert (uri != NULL);
  assert (buf != NULL);
  assert (count > 0);
  assert (offset >= 0);

  if (es_initialized_type == ES_NONE)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ES_NO_LOB_PATH, 0);
      return ER_ES_NO_LOB_PATH;
    }

  es_type = es_get_type (uri);
  if (es_type == ES_OWFS)
    {
#if defined(WINDOWS)
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ES_GENERAL, 2, "OwFS", "not supported");
      ret = ER_ES_GENERAL;
#else /* WINDOWS */
      ret = es_owfs_read_file (ES_OWFS_PATH_POS (uri), buf, count, offset);
      er_log_debug (ARG_FILE_LINE, "es_read_file: (es_owfs_read_file(%s, count %d, offset %ld) -> %d\n", uri, count,
		    offset, ret);
#endif /* !WINDOWS */
    }
  else if (es_type == ES_POSIX)
    {
#if defined (CS_MODE)
      ret = es_posix_read_file (ES_POSIX_PATH_POS (uri), buf, count, offset);
      er_log_debug (ARG_FILE_LINE, "es_read_file: es_posix_read_file(%s, count %d, offset %ld) -> %d\n", uri, count,
		    offset, ret);
#else /* CS_MODE */
      ret = xes_posix_read_file (ES_POSIX_PATH_POS (uri), buf, count, offset);
      er_log_debug (ARG_FILE_LINE, "es_read_file: xes_posix_read_file(%s, count %d, offset %ld) -> %d\n", uri, count,
		    offset, ret);
#endif /* SERVER_MODE || SA_MODE */
    }
  else if (es_type == ES_LOCAL)
    {
      ret = es_local_read_file (ES_LOCAL_PATH_POS (uri), buf, count, offset);
      er_log_debug (ARG_FILE_LINE, "es_read_file: es_local_read_file(%s, count %d, offset %ld) -> %d\n", uri, count,
		    offset, ret);
    }
  else
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ES_INVALID_PATH, 1, uri);
      return ER_ES_INVALID_PATH;
    }

  return ret;
}
Exemplo n.º 9
0
/*
 * pt_register_parser () - registers parser as existing by creating free list
 *   return: NO_ERROR on success, non-zero for ERROR
 *   parser(in):
 */
static int
pt_register_parser (const PARSER_CONTEXT * parser)
{
  int idhash;
  PARSER_NODE_FREE_LIST *free_list;
#if defined(SERVER_MODE)
  int rv;
#endif /* SERVER_MODE */

  /* find free list for for this id */
  idhash = parser->id % HASH_NUMBER;
#if defined(SERVER_MODE)
  MUTEX_LOCK (rv, free_lists_lock);
#endif /* SERVER_MODE */
  free_list = parser_Node_free_lists[idhash];
  while (free_list != NULL && free_list->parser_id != parser->id)
    {
      free_list = free_list->next;
    }

  if (free_list == NULL)
    {
      /* this is the first time this parser allocated a node. */
      /* set up a free list. This will only be done once per parser. */

      free_list =
	(PARSER_NODE_FREE_LIST *) calloc (sizeof (PARSER_NODE_FREE_LIST), 1);
      if (free_list == NULL)
	{
#if defined(SERVER_MODE)
	  MUTEX_UNLOCK (free_lists_lock);
#endif /* SERVER_MODE */
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY,
		  1, sizeof (PARSER_NODE_FREE_LIST));
	  return ER_FAILED;
	}
      free_list->parser_id = parser->id;
      free_list->next = parser_Node_free_lists[idhash];
      parser_Node_free_lists[idhash] = free_list;
    }
  else
    {
#if defined(SERVER_MODE)
      MUTEX_UNLOCK (free_lists_lock);
#endif /* SERVER_MODE */
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_GENERIC_ERROR, 0);
      return ER_FAILED;
    }
#if defined(SERVER_MODE)
  MUTEX_UNLOCK (free_lists_lock);
#endif /* SERVER_MODE */
  return NO_ERROR;
}
Exemplo n.º 10
0
/*
 * css_gethostid() - returns the hex number that represents this hosts
 *                   internet address
 *   return: pseudo-hostid if succesful, 0 if not
 */
unsigned int
css_gethostid (void)
{
  struct hostent *hp;
  char hostname[MAXHOSTNAMELEN];
  unsigned int inaddr;
  unsigned int retval;

#if !defined(SERVER_MODE)
  if (css_windows_startup () < 0)
    {
      return 0;
    }
#endif /* not SERVER_MODE */

  retval = 0;
  if (gethostname (hostname, MAXHOSTNAMELEN) == SOCKET_ERROR)
    {
      css_Wsa_error = CSS_ER_WINSOCK_HOSTNAME;
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_CSS_WINSOCK_HOSTNAME, 1, WSAGetLastError ());
    }
  else
    {
      inaddr = inet_addr (hostname);
      if (inaddr != INADDR_NONE)
	{
	  retval = inaddr;
	}
      else
	{
	  hp = gethostbyname (hostname);
	  if (hp != NULL)
	    {
	      retval = (*(unsigned int *) hp->h_addr);
	    }
	  else
	    {
	      css_Wsa_error = CSS_ER_WINSOCK_HOSTID;
	      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_CSS_WINSOCK_HOSTID, 1, WSAGetLastError ());
	    }
	}
    }

#if !defined(SERVER_MODE)
  css_windows_shutdown ();
#endif /* not SERVER_MODE */

  return retval;
}
Exemplo n.º 11
0
/*
 * es_get_file_size
 *
 * return: file size or -1 on error
 * uri(in):
*/
off_t
es_get_file_size (const char *uri)
{
  off_t ret;
  ES_TYPE es_type;

  assert (uri != NULL);

  if (es_initialized_type == ES_NONE)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ES_NO_LOB_PATH, 0);
      return ER_ES_NO_LOB_PATH;
    }

  es_type = es_get_type (uri);
  if (es_type == ES_OWFS)
    {
#if defined(WINDOWS)
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ES_GENERAL, 2, "OwFS", "not supported");
      ret = ER_ES_GENERAL;
#else /* WINDOWS */
      ret = es_owfs_get_file_size (ES_OWFS_PATH_POS (uri));
      er_log_debug (ARG_FILE_LINE, "es_copy_file: es_owfs_get_file_size(%s) -> %d\n", uri, ret);
#endif /* !WINDOWS */
    }
  else if (es_type == ES_POSIX)
    {
#if defined (CS_MODE)
      ret = es_posix_get_file_size (ES_POSIX_PATH_POS (uri));
      er_log_debug (ARG_FILE_LINE, "es_copy_file: es_posix_get_file_size(%s) -> %d\n", uri, ret);
#else /* CS_MODE */
      ret = xes_posix_get_file_size (ES_POSIX_PATH_POS (uri));
      er_log_debug (ARG_FILE_LINE, "es_copy_file: xes_posix_get_file_size(%s) -> %d\n", uri, ret);
#endif /* SERVER_MODE || SA_MODE */
    }
  else if (es_type == ES_LOCAL)
    {
      ret = es_local_get_file_size (ES_LOCAL_PATH_POS (uri));
      er_log_debug (ARG_FILE_LINE, "es_copy_file: es_local_get_file_size(%s) -> %d\n", uri, ret);
    }
  else
    {
      ret = -1;
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_ES_INVALID_PATH, 1, uri);
    }

  return ret;
}
Exemplo n.º 12
0
/*
 * otable_find_class - Locate the class table entry for a class.
 *    return: class table
 *    class(in): class object
 * Note:
 *    If one is not already on the list, a new one is created, added
 *    to the list and returned.
 */
CLASS_TABLE *
otable_find_class (MOP class_)
{
  CLASS_TABLE *table = Classes;

  while (table != NULL && table->class_ != class_)
    {
      table = table->next;
    }
  if (table == NULL)
    {
      table = (CLASS_TABLE *) malloc (sizeof (CLASS_TABLE));
      if (table == NULL)
	{
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_LDR_MEMORY_ERROR, 0);
	}
      else
	{
	  table->next = Classes;
	  Classes = table;
	  table->class_ = class_;
	  table->instances = NULL;
	  table->count = 0;
	  table->presize = 0;
	  table->total_inserts = 0;
	}
    }

  return (table);
}
Exemplo n.º 13
0
/*
 * realloc_instance_table - Extends the instance array within a CLASS_TABLE.
 *    return: NO_ERROR if successful, error code otherwise
 *    table(in/out): class table to extend
 *    newcount(in): new size of the instance table
 */
static int
realloc_instance_table (CLASS_TABLE * table, int newcount)
{
  INST_INFO *tmp_inst_info;
  int i;

  /*
   * only do this if the new count is larger than the existing
   * table, shouldn't see this
   */
  if (newcount > table->count)
    {
      tmp_inst_info =
	(INST_INFO *) realloc (table->instances,
			       newcount * sizeof (INST_INFO));
      if (tmp_inst_info == NULL)
	{
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_LDR_MEMORY_ERROR, 0);
	  return er_errid ();
	}

      for (i = table->count; i < newcount; i++)
	{
	  tmp_inst_info[i].flags = 0;
	  OID_SET_NULL (&(tmp_inst_info[i].oid));
	}

      table->instances = tmp_inst_info;
      table->count = newcount;
    }
  return NO_ERROR;
}
Exemplo n.º 14
0
/*
 * msgcat_open - open a message catalog
 *   return: message catalog descriptor MSG_CATD or NULL
 *   name(in): message catalog file name
 *
 * Note: File name will be converted to a full path name with the the root
 *       directory prefix.
 *       The returned MSG_CATD is allocated with malloc(). It will be freed in
 *       msgcat_close().
 */
MSG_CATD
msgcat_open (const char *name)
{
  nl_catd catd;
  MSG_CATD msg_catd;
  char path[PATH_MAX];

  /* $CUBRID/msg/$CUBRID_MSG_LANG/'name' */
  envvar_localedir_file (path, PATH_MAX, lang_get_msg_Loc_name (), name);
  catd = catopen (path, 0);
  if (catd == NULL)
    {
      /* try once more as default language */
      envvar_localedir_file (path, PATH_MAX, LANG_NAME_DEFAULT, name);
      catd = catopen (path, 0);
      if (catd == NULL)
	{
	  return NULL;
	}
    }

  msg_catd = (MSG_CATD) malloc (sizeof (*msg_catd));
  if (msg_catd == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, sizeof (*msg_catd));
      catclose (catd);
      return NULL;
    }

  msg_catd->file = strdup (path);
  msg_catd->catd = (void *) catd;

  return msg_catd;
}
Exemplo n.º 15
0
/*
 * logwr_flush_header_page -
 *
 * return:
 * Note:
 */
void
logwr_flush_header_page (void)
{
  PAGEID phy_pageid;
  PAGEID logical_pageid;
  int nbytes;

  if (logwr_Gl.loghdr_pgptr == NULL)
    {
      return;
    }

  /* flush current archiving status */
  logwr_Gl.hdr.nxarv_num = logwr_Gl.last_arv_num;
  logwr_Gl.hdr.last_deleted_arv_num = logwr_Gl.last_deleted_arv_num;
  logwr_Gl.hdr.nxarv_pageid = logwr_Gl.last_arv_fpageid;
  logwr_Gl.hdr.nxarv_phy_pageid
    = logwr_to_physical_pageid (logwr_Gl.last_arv_fpageid);

  memcpy (logwr_Gl.loghdr_pgptr->area, &logwr_Gl.hdr, sizeof (logwr_Gl.hdr));

  logical_pageid = LOGPB_HEADER_PAGE_ID;
  phy_pageid = logwr_to_physical_pageid (logical_pageid);

  /* logwr_Gl.append_vdes is only changed
   * while starting or finishing or recovering server.
   * So, log cs is not needed.
   */
  if (fileio_write (NULL, logwr_Gl.append_vdes, logwr_Gl.loghdr_pgptr,
		    phy_pageid, LOG_PAGESIZE) == NULL
      || (logwr_Gl.mode != LOGWR_MODE_ASYNC
	  && fileio_synchronize (NULL, logwr_Gl.append_vdes,
				 logwr_Gl.active_name)) == NULL_VOLDES)
    {

      if (er_errid () == ER_IO_WRITE_OUT_OF_SPACE)
	{
	  nbytes = ((logwr_Gl.hdr.npages + 1 - logical_pageid) *
		    logwr_Gl.hdr.db_logpagesize);
	  er_set (ER_FATAL_ERROR_SEVERITY, ARG_FILE_LINE,
		  ER_LOG_WRITE_OUT_OF_SPACE, 4, logical_pageid, phy_pageid,
		  logwr_Gl.active_name, nbytes);
	}
      else
	{
	  er_set_with_oserror (ER_FATAL_ERROR_SEVERITY, ARG_FILE_LINE,
			       ER_LOG_WRITE, 3, logical_pageid, phy_pageid,
			       logwr_Gl.active_name);
	}
    }

  /* save last checkpoint pageid */
  logwr_Gl.last_chkpt_pageid = logwr_Gl.hdr.chkpt_lsa.pageid;

  er_log_debug (ARG_FILE_LINE,
		"logwr_flush_header_page, ha_server_state=%s, ha_file_status=%s\n",
		css_ha_server_state_string (logwr_Gl.hdr.ha_server_state),
		logwr_Gl.hdr.ha_file_status ==
		LOG_HA_FILESTAT_SYNCHRONIZED ? "sync" : "unsync");
}
Exemplo n.º 16
0
/*
 * db_constrain_non_null() - This function sets the state of an attribute's
 *                           NON_NULL constraint.
 * return : error code
 * class(in): class or instance object
 * name(in) : attribute name
 * class_attribute(in): flag indicating class attribute status
 *        (0 if this is not a class attribute,
 *         non-zero if this is a class attribute)
 * on_or_off(in): non-zero if constraint is to be enabled
 *
 */
int
db_constrain_non_null (MOP class_, const char *name, int class_attribute, int on_or_off)
{
  const char *att_names[2];
  int retval;

  att_names[0] = name;
  att_names[1] = NULL;
  if (on_or_off)
    {
      bool has_nulls = false;
      retval = do_check_rows_for_null (class_, name, &has_nulls);
      if (retval != NO_ERROR)
	{
	  return retval;
	}

      if (has_nulls)
	{
	  retval = ER_SM_ATTR_NOT_NULL;
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, retval, 1, name);
	  return retval;
	}

      retval = db_add_constraint (class_, DB_CONSTRAINT_NOT_NULL, NULL, att_names, class_attribute);
    }
  else
    {
      retval = db_drop_constraint (class_, DB_CONSTRAINT_NOT_NULL, NULL, att_names, class_attribute);
    }

  return (retval);
}
Exemplo n.º 17
0
/*
 * cursor_get_tuple_value () -
 *   return: NO_ERROR on all ok, ER status( or ER_FAILED) otherwise
 *   c_id(in): Cursor Identifier
 *   index(in):
 *   value(in/out):
 * Note: The data value of the current cursor tuple at the position
 *       pecified is fetched. If the position specified by index is
 *       not a valid position number, or if the cursor is not
 *       currently pointing to a tuple, then necessary error codes are
 *       returned.
 */
int
cursor_get_tuple_value (CURSOR_ID * curor_id_p, int index, DB_VALUE * value_p)
{
  char *tuple_p;

  if (curor_id_p->is_oid_included == true)
    {
      index++;
    }

  if (index < 0 || index >= curor_id_p->list_id.type_list.type_cnt)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_QPROC_INVALID_TPLVAL_INDEX,
	      1, index);
      return ER_FAILED;
    }

  tuple_p = cursor_peek_tuple (curor_id_p);
  if (tuple_p == NULL)
    {
      return ER_FAILED;
    }

  return cursor_get_tuple_value_from_list (curor_id_p, index, value_p,
					   tuple_p);
}
Exemplo n.º 18
0
/*    
* hb_make_set_hbp_register () - 
*   return: 
*
*   type(in):
*/
static HBP_PROC_REGISTER *
hb_make_set_hbp_register (int type)
{
  int error;

  HBP_PROC_REGISTER *hbp_register;
  char *p, *last;
  int argc;
  char **argv;

  hbp_register = (HBP_PROC_REGISTER *) malloc (sizeof (HBP_PROC_REGISTER));
  if (NULL == hbp_register)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, sizeof (HBP_PROC_REGISTER));
      return (NULL);
    }

  memset ((void *) hbp_register, 0, sizeof (HBP_PROC_REGISTER));
  hbp_register->pid = htonl (getpid ());
  hbp_register->type = htonl (type);
  strncpy (hbp_register->exec_path, hb_Exec_path, sizeof (hbp_register->exec_path) - 1);

  p = (char *) &hbp_register->args[0];
  last = (char *) (p + sizeof (hbp_register->args));
  for (argc = 0, argv = hb_Argv; *argv && argc < HB_MAX_NUM_PROC_ARGV; argc++, argv++)
    {
      p += snprintf (p, MAX ((last - p), 0), "%s ", *argv);
      strncpy ((char *) hbp_register->argv[argc], *argv, (HB_MAX_SZ_PROC_ARGV - 1));
    }

  return (hbp_register);
}
Exemplo n.º 19
0
Arquivo: sha1.c Projeto: CUBRID/cubrid
int
SHA1Compute (const unsigned char *message_array, unsigned length, SHA1Hash * hash)
{
  SHA1Context context;

  assert (message_array != NULL);
  assert (hash != NULL);

  SHA1Reset (&context);
  SHA1Input (&context, message_array, length);

  if (!SHA1Result (&context))
    {
      assert (false);
      /* TODO: Set an appropiate error message. */
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_GENERIC_ERROR, 0);
      return ER_FAILED;
    }

  hash->h[0] = (INT32) context.Message_Digest[0];
  hash->h[1] = (INT32) context.Message_Digest[1];
  hash->h[2] = (INT32) context.Message_Digest[2];
  hash->h[3] = (INT32) context.Message_Digest[3];
  hash->h[4] = (INT32) context.Message_Digest[4];

  return NO_ERROR;
}
Exemplo n.º 20
0
/*
 * disk_reserve_instance - This is used to reserve space for an instance that
 * was referenced in the load file but has not yet been defined.
 *    return: NO_ERROR if successful, error code otherwise
 *    classop(in): class
 *    oid(in): returned instance OID
 */
int
disk_reserve_instance (MOP classop, OID * oid)
{
  int error = NO_ERROR;
  SM_CLASS *class_;
  HFID *hfid;
  int expected;

  class_ = (SM_CLASS *) locator_fetch_class (classop, DB_FETCH_READ);
  if (class_ == NULL)
    {
      error = er_errid ();
    }
  else
    {
      expected = estimate_object_size (class_);
      hfid = get_class_heap (classop, class_);
      if (hfid == NULL)
	{
	  error = er_errid ();
	}
      else
	{
	  if (heap_assign_address_with_class_oid (NULL, hfid, oid, expected,
						  ws_oid (classop)) !=
	      NO_ERROR)
	    {
	      error = ER_LDR_CANT_INSERT;
	      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
	    }
	}
    }

  return error;
}
Exemplo n.º 21
0
/*
 * bh_insert () - insert an element in the correct position in the heap
 * return : error code or NO_ERROR
 * heap (in) : heap
 * elem (in) : new element
 */
int
bh_insert (BINARY_HEAP * heap, BH_ELEM elem)
{
  if (heap->element_count != 0)
    {
      assert_release (heap->state == BH_HEAP_CONSISTENT);
    }
  else
    {
      /* This is the first element, set the consistent property */
      heap->state = BH_HEAP_CONSISTENT;
    }

  if (heap->element_count >= heap->max_capacity)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_BINARY_HEAP_OUT_OF_RANGE, 0);
      return ER_BINARY_HEAP_OUT_OF_RANGE;
    }

  heap->members[heap->element_count] = elem;
  heap->element_count++;
  bh_up_heap (heap, heap->element_count - 1);

  return NO_ERROR;
}
Exemplo n.º 22
0
/*
 * log_zip_alloc - allocate LOG_ZIP structure
 *   return: LOG_ZIP structure or NULL if error
 *   length(in): log_zip data buffer to be allocated
 *   is_zip(in): to be used zip or not
 *
 * Note:
 */
LOG_ZIP *
log_zip_alloc (LOG_ZIP_SIZE_T size, bool is_zip)
{
  LOG_ZIP *log_zip = NULL;
  LOG_ZIP_SIZE_T buf_size = 0;

  buf_size = LOG_ZIP_BUF_SIZE (size);
  log_zip = (LOG_ZIP *) malloc (sizeof (LOG_ZIP));
  if (log_zip == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY,
	      1, sizeof (LOG_ZIP));

      return NULL;
    }
  log_zip->data_length = 0;

  log_zip->log_data = (lzo_bytep) malloc ((size_t) buf_size);
  if (log_zip->log_data == NULL)
    {
      free_and_init (log_zip);
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY,
	      1, buf_size);
      return NULL;
    }
  log_zip->buf_size = buf_size;

  if (is_zip)
    {
      /* lzo method is best speed : LZO1X_1_MEM_COMPRESS */
      log_zip->wrkmem = (lzo_bytep) malloc (LZO1X_1_MEM_COMPRESS);
      if (log_zip->wrkmem == NULL)
	{
	  free_and_init (log_zip->log_data);
	  free_and_init (log_zip);
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY,
		  1, LZO1X_1_MEM_COMPRESS);
	  return NULL;
	}
    }
  else
    {
      log_zip->wrkmem = NULL;
    }

  return log_zip;
}
Exemplo n.º 23
0
/*
 * log_unzip - decompress(unzip) log data into LOG_ZIP
 *   return: true on success, false on failure
 *   log_unzip(out): LOG_ZIP structure allocated by log_zip_alloc
 *   length(in): length of given data
 *   data(out): compressed log data
 */
bool
log_unzip (LOG_ZIP * log_unzip, LOG_ZIP_SIZE_T length, void *data)
{
  lzo_uint unzip_len;
  LOG_ZIP_SIZE_T org_len;
  LOG_ZIP_SIZE_T buf_size;
  int rc;

  assert (length > 0 && data != NULL);
  assert (log_unzip != NULL);

  /* get original legnth from the compressed data */
  memcpy (&org_len, data, sizeof (LOG_ZIP_SIZE_T));

  if (org_len <= 0)
    return false;
  unzip_len = (lzo_uint) org_len;
  buf_size = LOG_ZIP_BUF_SIZE (org_len);
  length -= sizeof (LOG_ZIP_SIZE_T);

  if (buf_size > log_unzip->buf_size)
    {
      if (log_unzip->log_data)
	{
	  free_and_init (log_unzip->log_data);
	}

      log_unzip->log_data = (unsigned char *) malloc (buf_size);
      if (log_unzip->log_data == NULL)
	{
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY,
		  1, buf_size);
	}
      log_unzip->buf_size = buf_size;
    }

  if (log_unzip->log_data == NULL)
    {
      log_unzip->data_length = 0;
      log_unzip->buf_size = 0;
      return false;
    }

  rc = lzo1x_decompress_safe ((lzo_bytep) data + sizeof (LOG_ZIP_SIZE_T),
			      (lzo_uint) length, log_unzip->log_data,
			      &unzip_len, NULL);

  if (rc == LZO_E_OK)
    {
      log_unzip->data_length = unzip_len;
      /* if the uncompressed data length != original length,
       * then it means that uncompression failed */
      if (unzip_len == (lzo_uint) org_len)
	{
	  return true;
	}
    }
  return false;
}
Exemplo n.º 24
0
static int
set_server_error (int error)
{
  int server_error;

  switch (error)
    {
    case CANT_ALLOC_BUFFER:
      server_error = ER_NET_CANT_ALLOC_BUFFER;
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, server_error, 0);
      break;
    case RECORD_TRUNCATED:
      server_error = ER_NET_DATA_TRUNCATED;
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, server_error, 0);
      break;
    case REQUEST_REFUSED:
      server_error = er_errid ();
      break;
    case SERVER_ABORTED:
      server_error = er_errid ();
      /* those errors are generated by the net_server_request()
       * so that do not fall to server crash handling */
      switch (server_error)
	{
	case ER_DB_NO_MODIFICATIONS:
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, server_error, 0);
	  return (server_error);
	case ER_AU_DBA_ONLY:
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, server_error, 1, "");
	  return (server_error);
	}
      /* no break; fall through */
    default:
      server_error = ER_NET_SERVER_CRASHED;
      er_set_with_oserror (ER_ERROR_SEVERITY, ARG_FILE_LINE, server_error, 0);
      break;
    }

  er_log_debug (ARG_FILE_LINE, "set_server_error(%d) server_error %d\n",
		error, server_error);

  db_Connect_status = DB_CONNECTION_STATUS_NOT_CONNECTED;

  return (server_error);
}
Exemplo n.º 25
0
/*
 * disk_insert_instance - This inserts a new object in the database given a
 * "descriptor" for the object.
 *    return: NO_ERROR if successful, error code otherwise
 *    classop(in): class object
 *    obj(in): object description
 *    oid(in): oid of the destination
 */
int
disk_insert_instance (MOP classop, DESC_OBJ * obj, OID * oid)
{
  int error = NO_ERROR;
  HFID *hfid;
  int newsize;
  bool has_indexes;

  Diskrec->length = 0;
  if (desc_obj_to_disk (obj, Diskrec, &has_indexes))
    {
      /* make the record larger */
      newsize = -Diskrec->length + DB_PAGESIZE;
      free_recdes (Diskrec);
      Diskrec = alloc_recdes (newsize);
      /* try one more time */
      if (Diskrec == NULL || desc_obj_to_disk (obj, Diskrec, &has_indexes) != 0)
	{
	  error = ER_LDR_CANT_TRANSFORM;
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
	}
    }

  if (!error)
    {
      hfid = get_class_heap (classop, obj->class_);
      if (hfid == NULL)
	{
	  assert (er_errid () != NO_ERROR);
	  error = er_errid ();
	}
      else
	{
	  HEAP_OPERATION_CONTEXT context;

	  /* set up context */
	  heap_create_insert_context (&context, hfid, WS_OID (classop), Diskrec, NULL, false);

	  /* oid is set here as a side effect */
	  if (heap_insert_logical (NULL, &context) != NO_ERROR)
	    {
	      assert (er_errid () != NO_ERROR);
	      error = er_errid ();
	    }
	  else if (has_indexes)
	    {
	      COPY_OID (oid, &context.res_oid);
	      error = update_indexes (WS_OID (classop), oid, Diskrec);
	    }
	  else
	    {
	      COPY_OID (oid, &context.res_oid);
	    }
	}
    }
  return (error);
}
Exemplo n.º 26
0
/*
 * disk_update_instance - This updates an object that had previously been
 * reserved with the actual contents.
 *    return: NO_ERROR if successful, error code otherwise
 *    classop(in): class object
 *    obj(in): description of object
 *    oid(in): destination oid
 */
int
disk_update_instance (MOP classop, DESC_OBJ * obj, OID * oid)
{
  int error = NO_ERROR;
  HFID *hfid;
  int newsize;
  bool has_indexes = false;

  Diskrec->length = 0;
  if (desc_obj_to_disk (obj, Diskrec, &has_indexes))
    {
      /* make the record larger */
      newsize = -Diskrec->length + DB_PAGESIZE;
      free_recdes (Diskrec);
      Diskrec = alloc_recdes (newsize);
      /* try one more time */
      if (Diskrec == NULL || desc_obj_to_disk (obj, Diskrec, &has_indexes) != 0)
	{
	  error = ER_LDR_CANT_TRANSFORM;
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
	}
    }
  if (!error)
    {
      hfid = get_class_heap (classop, obj->class_);
      if (hfid == NULL)
	{
	  assert (er_errid () != NO_ERROR);
	  error = er_errid ();
	}
      else
	{
	  HEAP_OPERATION_CONTEXT update_context;

	  heap_create_update_context (&update_context, hfid, oid, WS_OID (classop), Diskrec, NULL, UPDATE_INPLACE_NONE);

	  if (heap_update_logical (NULL, &update_context) != NO_ERROR)
	    {
	      assert (er_errid () != NO_ERROR);
	      error = er_errid ();
	    }

	  if (update_context.is_logical_old)
	    {
	      fprintf (stdout,
		       msgcat_message (MSGCAT_CATALOG_UTILS, MSGCAT_UTIL_SET_LOADDB, LOADDB_MSG_UPDATE_WARNING));
	    }
	  else if (has_indexes)
	    {
	      error = update_indexes (WS_OID (classop), oid, Diskrec);
	    }
	}
    }

  return (error);
}
Exemplo n.º 27
0
/*
 * logwr_register_writer_entry -
 *
 * return:
 *
 *   wr_entry_p(out):
 *   id(in):
 *   fpageid(in):
 *   mode(in):
 *
 * Note:
 */
static int
logwr_register_writer_entry (LOGWR_ENTRY ** wr_entry_p,
			     THREAD_ENTRY * thread_p,
			     PAGEID fpageid, int mode)
{
  LOGWR_ENTRY *entry;
  int rv;
  LOGWR_INFO *writer_info = &log_Gl.writer_info;

  *wr_entry_p = NULL;
  LOG_MUTEX_LOCK (rv, writer_info->wr_list_mutex);

  entry = writer_info->writer_list;
  while (entry)
    {
      if (entry->thread_p == thread_p)
	{
	  break;
	}
      entry = entry->next;
    }

  if (entry == NULL)
    {
      entry = malloc (sizeof (LOGWR_ENTRY));
      if (entry == NULL)
	{
	  LOG_MUTEX_UNLOCK (writer_info->wr_list_mutex);
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY,
		  1, sizeof (LOGWR_ENTRY));
	  return ER_OUT_OF_VIRTUAL_MEMORY;
	}

      entry->thread_p = thread_p;
      entry->fpageid = fpageid;
      entry->mode = mode;
      entry->status = LOGWR_STATUS_DELAY;

      entry->next = writer_info->writer_list;
      writer_info->writer_list = entry;
    }
  else
    {
      entry->fpageid = fpageid;
      entry->mode = mode;
      if (entry->status != LOGWR_STATUS_DELAY)
	{
	  entry->status = LOGWR_STATUS_WAIT;
	}
    }

  LOG_MUTEX_UNLOCK (writer_info->wr_list_mutex);
  *wr_entry_p = entry;

  return NO_ERROR;
}
Exemplo n.º 28
0
/*
 * log_zip - compress(zip) log data into LOG_ZIP
 *   return: true on success, false on failure
 *   log_zip(in/out): LOG_ZIP structure allocated by log_zip_alloc
 *   length(in): length of given data
 *   data(in): log data to be compressed
 */
bool
log_zip (LOG_ZIP * log_zip, LOG_ZIP_SIZE_T length, const void *data)
{
  lzo_uint zip_len = 0;
  LOG_ZIP_SIZE_T buf_size;
  int rc;

  assert (length > 0 && data != NULL);
  assert (log_zip != NULL);

  log_zip->data_length = 0;

  buf_size = LOG_ZIP_BUF_SIZE (length);
  if (buf_size > log_zip->buf_size)
    {
      if (log_zip->log_data)
	{
	  free_and_init (log_zip->log_data);
	}

      log_zip->log_data = (unsigned char *) malloc (buf_size);
      if (log_zip->log_data == NULL)
	{
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY,
		  1, buf_size);
	}
      log_zip->buf_size = buf_size;
    }

  if (log_zip->log_data == NULL)
    {
      log_zip->data_length = 0;
      log_zip->buf_size = 0;
      return false;
    }

  /* save original data length */
  memcpy (log_zip->log_data, &length, sizeof (LOG_ZIP_SIZE_T));

  rc = lzo1x_1_compress ((lzo_bytep) data,
			 (lzo_uint) length,
			 log_zip->log_data + sizeof (LOG_ZIP_SIZE_T),
			 &zip_len, log_zip->wrkmem);
  if (rc == LZO_E_OK)
    {
      log_zip->data_length = zip_len + sizeof (LOG_ZIP_SIZE_T);
      /* if the compressed data length >= orginal length,
       * then it means that compression failed */
      if (log_zip->data_length < length)
	{
	  return true;
	}
    }
  return false;
}
Exemplo n.º 29
0
/*
 * pt_report_to_ersys () - report query compilation error by
 *                         setting global ER state
 *   return:
 *   parser(in): handle to parser used to process the query
 *   error_type(in): syntax, semantic, or execution
 */
void
pt_report_to_ersys (const PARSER_CONTEXT * parser, const PT_ERROR_TYPE error_type)
{
  PT_NODE *error_node;
  int err;
  char buf[1000];

  error_node = parser->error_msgs;
  if (error_node && error_node->node_type == PT_ZZ_ERROR_MSG)
    {
#if 0				/* TODO */
      assert (er_errid () != NO_ERROR);
#endif
      err = er_errid ();
      if (!ER_IS_LOCK_TIMEOUT_ERROR (err) && !ER_IS_SERVER_DOWN_ERROR (err))
	{
	  switch (error_type)
	    {
	    case PT_SYNTAX:
	      er_set (ER_SYNTAX_ERROR_SEVERITY, ARG_FILE_LINE, ER_PT_SYNTAX, 2,
		      error_node->info.error_msg.error_message, "");
	      break;
	    case PT_SEMANTIC:
	    default:
	      er_set (ER_SYNTAX_ERROR_SEVERITY, ARG_FILE_LINE, ER_PT_SEMANTIC, 2,
		      error_node->info.error_msg.error_message, "");
	      break;
	    case PT_EXECUTION:
	      er_set (ER_SYNTAX_ERROR_SEVERITY, ARG_FILE_LINE, ER_PT_EXECUTE, 2,
		      error_node->info.error_msg.error_message, "");
	      break;
	    }
	}
      return;
    }

  /* a system error reporting error messages */
  sprintf (buf, "Internal error- reporting %s error.",
	   (error_type == PT_SYNTAX ? "syntax" : (error_type == PT_SEMANTIC ? "semantic" : "execution")));

  er_set (ER_SYNTAX_ERROR_SEVERITY, ARG_FILE_LINE, ER_PT_EXECUTE, 2, buf, "");
}
Exemplo n.º 30
0
/*
 * db_object_describe() -  get a DB_QUERY_TYPE descriptor of the named
 *                         attributes of a given object
 *   return:  int (non-zero in case of error)
 *   obj_mop(in): a DB_OBJECT in the workspace
 *   num_attrs(in): number of names in attrs array
 *   attrs(in): an array of null-terminated character strings
 *   col_spec(out): a new DB_QUERY_TYPE structure
 */
int
db_object_describe (DB_OBJECT * obj_mop, int num_attrs, const char **attrs, DB_QUERY_TYPE ** col_spec)
{
  DB_QUERY_TYPE *t;
  int i, bytes, attrid, shared, err = NO_ERROR;
  MOP class_mop;
  const char **name;
  SM_DOMAIN *tmp_dom;

  CHECK_CONNECT_ERROR ();

  if (!col_spec)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OBJ_INVALID_ARGUMENTS, 0);
      return -1;
    }

  *col_spec = NULL;
  if ((class_mop = WS_CLASS_MOP (obj_mop)) == NULL)
    return -1;

  *col_spec = db_alloc_query_format (num_attrs);
  if (*col_spec == NULL)
    return -1;

  for (i = 0, t = *col_spec, name = attrs; i < num_attrs && t && name && err == NO_ERROR; i++, t = t->next, name++)
    {
      t->db_type = sm_att_type_id (class_mop, *name);
      t->size = pt_find_size_from_dbtype (t->db_type);
      t->name = (char *) malloc (bytes = 1 + strlen (*name));
      if (t->name)
	strcpy ((char *) t->name, *name);
      else
	{
	  db_free_query_format (*col_spec);
	  *col_spec = NULL;
	  return -1;
	}

      t->attr_name = NULL;
      t->src_domain = NULL;
      err = sm_att_info (class_mop, *name, &attrid, &tmp_dom, &shared, 0);
      t->domain = regu_cp_domain (tmp_dom);
    }

  if (err != NO_ERROR)
    {
      db_free_query_format (*col_spec);
      *col_spec = NULL;
      return -1;
    }

  return 0;
}