<commit_before>/*
 * The contents of this file are subject to the MonetDB Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.monetdb.org/Legal/MonetDBLicense
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * The Original Code is the MonetDB Database System.
 *
 * The Initial Developer of the Original Code is CWI.
 * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
 * Copyright August 2008-2011 MonetDB B.V.
 * All Rights Reserved.
 */

/*
 * This code was created by <NAME> (mostly during Christmas 98/99).
 * This code is LGPL. Please ensure that this message remains in future
 * distributions and uses of this code (thats about all I get out of it).
 * - <NAME> <EMAIL>
 * 
 * This file has been modified for the MonetDB project.  See the file
 * Copyright in this directory for more information.
 */

/**********************************************************************
 * SQLExecDirect()
 * CLI Compliance: ISO 92
 *
 * Author: <NAME>, <NAME>
 * Date  : 30 Aug 2002
 *
 **********************************************************************/

#include "ODBCGlobal.h"
#include "ODBCStmt.h"
#include "ODBCUtil.h"

static struct errors {
	const char *error;
	const char *msg;
} errors[] = {
	{"syntax error", "42000"},
	{"DROP TABLE: no such table", "42S02"},
	{"DROP VIEW: unknown view", "42S02"},
	{"ALTER TABLE: no such table", "42S02"},
	{"CREATE INDEX: no such table", "42S02"},
	{"SELECT: no such table", "42S02"},
	{"INSERT INTO: no such table", "42S02"},
	{"DELETE FROM: no such table", "42S02"},
	{"UPDATE: no such table", "42S02"},
	{"CONSTRAINT FOREIGN KEY: no such table", "42S02"},
	{NULL, NULL},		/* sentinel */
};

const char *
ODBCErrorType(const char *msg, const char **emsg)
{
	struct errors *e;

	if (strlen(msg) > 6 && msg[5] == ':' &&
	    ((msg[0] >= '0' && msg[0] <= '9') ||
	     (msg[0] >= 'A' && msg[0] <= 'Z')) &&
	    ((msg[1] >= '0' && msg[1] <= '9') ||
	     (msg[1] >= 'A' && msg[1] <= 'Z')) &&
	    ((msg[2] >= '0' && msg[2] <= '9') ||
	     (msg[2] >= 'A' && msg[2] <= 'Z')) &&
	    ((msg[3] >= '0' && msg[3] <= '9') ||
	     (msg[3] >= 'A' && msg[3] <= 'Z')) &&
	    ((msg[4] >= '0' && msg[4] <= '9') ||
	     (msg[4] >= 'A' && msg[4] <= 'Z')) &&
	    strncmp(msg, "ERROR", 5) != 0) {
		*emsg = msg + 6;
		while (**emsg == ' ')
			(*emsg)++;
		return msg;
	}

	*emsg = msg;
	for (e = errors; e->error != NULL; e++)
		if (strncmp(msg, e->error, strlen(e->error)) == 0)
			return e->msg;
	return NULL;
}

static SQLRETURN
ODBCExecDirect(ODBCStmt *stmt, SQLCHAR *StatementText, SQLINTEGER TextLength)
{
	char *query;
	MapiMsg ret;
	MapiHdl hdl;

	hdl = stmt->hdl;

	if (stmt->State >= EXECUTED1 ||
	    (stmt->State == EXECUTED0 && mapi_more_results(hdl))) {
		/* Invalid cursor state */
		addStmtError(stmt, "24000", NULL, 0);
		return SQL_ERROR;<commit_msg>ODBC: SQLSTATE is now terminated by !.<commit_after>/*
 * The contents of this file are subject to the MonetDB Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.monetdb.org/Legal/MonetDBLicense
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * The Original Code is the MonetDB Database System.
 *
 * The Initial Developer of the Original Code is CWI.
 * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
 * Copyright August 2008-2011 MonetDB B.V.
 * All Rights Reserved.
 */

/*
 * This code was created by <NAME> (mostly during Christmas 98/99).
 * This code is LGPL. Please ensure that this message remains in future
 * distributions and uses of this code (thats about all I get out of it).
 * - <NAME> <EMAIL>
 * 
 * This file has been modified for the MonetDB project.  See the file
 * Copyright in this directory for more information.
 */

/**********************************************************************
 * SQLExecDirect()
 * CLI Compliance: ISO 92
 *
 * Author: <NAME>, <NAME>
 * Date  : 30 Aug 2002
 *
 **********************************************************************/

#include "ODBCGlobal.h"
#include "ODBCStmt.h"
#include "ODBCUtil.h"

static struct errors {
	const char *error;
	const char *msg;
} errors[] = {
	{"syntax error", "42000"},
	{"SELECT: no such table", "42S02"},
	{"INSERT INTO: no such table", "42S02"},
	{"DELETE FROM: no such table", "42S02"},
	{"UPDATE: no such table", "42S02"},
	{"CONSTRAINT FOREIGN KEY: no such table", "42S02"},
	{NULL, NULL},		/* sentinel */
};

const char *
ODBCErrorType(const char *msg, const char **emsg)
{
	struct errors *e;

	if (strlen(msg) > 6 && msg[5] == '!' &&
	    ((msg[0] >= '0' && msg[0] <= '9') ||
	     (msg[0] >= 'A' && msg[0] <= 'Z')) &&
	    ((msg[1] >= '0' && msg[1] <= '9') ||
	     (msg[1] >= 'A' && msg[1] <= 'Z')) &&
	    ((msg[2] >= '0' && msg[2] <= '9') ||
	     (msg[2] >= 'A' && msg[2] <= 'Z')) &&
	    ((msg[3] >= '0' && msg[3] <= '9') ||
	     (msg[3] >= 'A' && msg[3] <= 'Z')) &&
	    ((msg[4] >= '0' && msg[4] <= '9') ||
	     (msg[4] >= 'A' && msg[4] <= 'Z'))) {
		*emsg = msg + 6;
		while (**emsg == ' ')
			(*emsg)++;
		return msg;
	}

	*emsg = msg;
	for (e = errors; e->error != NULL; e++)
		if (strncmp(msg, e->error, strlen(e->error)) == 0)
			return e->msg;
	return NULL;
}

static SQLRETURN
ODBCExecDirect(ODBCStmt *stmt, SQLCHAR *StatementText, SQLINTEGER TextLength)
{
	char *query;
	MapiMsg ret;
	MapiHdl hdl;

	hdl = stmt->hdl;

	if (stmt->State >= EXECUTED1 ||
	    (stmt->State == EXECUTED0 && mapi_more_results(hdl))) {
		/* Invalid cursor state */
		addStmtError(stmt, "24000", NULL, 0);
		return SQL_ERROR;
{'fraction_non_alphanumeric': 0.2184721764899572, 'fraction_numerical': 0.03490286466908133, 'mean_word_length': 3.581447963800905, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3610891', 'n_tokens_mistral': 2266, 'n_tokens_neox': 2084, 'n_words': 712}