⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isql.e

📁 firebird源代码
💻 E
📖 第 1 页 / 共 5 页
字号:
	return FALSE;	};FOR FLD IN RDB$FIELDS WITH    FLD.RDB$FIELD_NAME EQ field_name    if (!(strncmp (FLD.RDB$FIELD_NAME, "RDB$", 4) == 0 &&	  isdigit (FLD.RDB$FIELD_NAME[4]) &&	  FLD.RDB$SYSTEM_FLAG != 1))	is_domain = TRUE;END_FOR    ON_ERROR	ISQL_errmsg (isc_status);	return is_domain;    END_ERROR;return is_domain;}void ISQL_make_upper (    UCHAR	*str){/************************************** * *	I S Q L _ m a k e _ u p p e r * ************************************** * *	Force the name of a metadata object to *	uppercase. * **************************************/UCHAR	*p;if (!str)    return;for (p = str; *p; p++)    *p = UPPER7 (*p);}void ISQL_msg_get (    USHORT	number,    TEXT	*msg,    TEXT	*arg1,    TEXT	*arg2,    TEXT	*arg3,    TEXT	*arg4,    TEXT	*arg5){/************************************** * *	I S Q L _ m s g _ g e t * ************************************** * * Functional description *	Retrieve a message from the error file * **************************************/gds__msg_format (NULL_PTR, ISQL_MSG_FAC, number, MSG_LENGTH, msg,		 arg1, arg2, arg3, arg4, arg5);}void ISQL_print_validation (    IB_FILE	*fp,    ISC_QUAD	*blobid,    SSHORT	flag,    SLONG	*trans){/************************************** * *	I S Q L _ p r i n t _ v a l i d a t i o n * ************************************** * * Functional description *	This does some minor syntax adjustmet for extracting  *	validation blobs and computed fields. *	if it does not start with the word CHECK *	if this is a computed field blob,look for () or insert them. *	if flag == 0, this is a validation clause, *	if flag == 1, this is a computed field * **************************************/SLONG	*blob;USHORT	length;TEXT	*buffer, *p;SSHORT	issql = FALSE, firsttime = TRUE;/* Don't bother with null blobs */if (blobid->isc_quad_high == 0)    return;buffer = (TEXT *) ISQL_ALLOC (BUFFER_LENGTH512);blob = NULL;if (isc_open_blob (isc_status, &DB, &trans, &blob, blobid))    {    ISQL_errmsg (isc_status);    if (buffer)	ISQL_FREE (buffer);    return;    }while (!isc_get_segment (isc_status, &blob, &length,	(USHORT) (BUFFER_LENGTH512 - 1),	buffer) || isc_status [1] == isc_segment)    {    buffer [length] = 0;    p = buffer;    if (flag)	{	/* computed field SQL syntax correction */	while (isspace (*p))		p++;	if (*p == '(')	    issql = TRUE;	}    else  	{	/* Validation SQL syntax correction */	while (isspace (*p))		p++;	if (!strncmp (p, "check", 5) || !strncmp (p, "CHECK", 5))	    issql = TRUE;	}    if (firsttime)	{	firsttime = FALSE;	if (!issql)	    {	    sprintf (Print_buffer, "%s ", (flag ? "/* " : "("));	    ISQL_printf (fp, Print_buffer);	    }	}	    ISQL_printf (fp, buffer);    }    if (!issql)	{	sprintf (Print_buffer, "%s", (flag ? " */" : ")"));	ISQL_printf (fp, Print_buffer);	}isc_close_blob (isc_status, &blob);if (isc_status [1])    ISQL_errmsg (isc_status);if (buffer)    ISQL_FREE (buffer);}void ISQL_printf(	IB_FILE	*fp, 	TEXT	*buffer){/************************************** * *	I S Q L _ p r i n t f * ************************************** * *	Centralized printing facility * **************************************/#ifndef GUI_TOOLSib_fprintf (fp, "%s", buffer);#elseSCHAR           *pszStartPos, *psChar, cSavChar;/* Check buffer to make sure we have data */if (!*buffer)    return;/* Windows ISQL output routine */psChar          = buffer;pszStartPos     = buffer;/* If first char is newline then print PC newline */if (*psChar == '\n')    {    PaintOutputWindow (NEWLINE);    ib_fprintf (fp, "%s", "\n");    pszStartPos = buffer + 1;    }psChar++;/* Step through output buffer displaying output when a newline is reached */for (; *psChar != NULL; psChar++)    {   if (*psChar == '\n' && *(psChar - 1) != '\r')       {       cSavChar = *psChar;       *psChar  = NULL;       /* Don't print the Null */       if (*pszStartPos)           {           PaintOutputWindow (pszStartPos);           ib_fprintf (fp, "%s", pszStartPos);    	   }       PaintOutputWindow (NEWLINE);       ib_fprintf (fp, "%s", "\n");       *psChar  = cSavChar;       pszStartPos  = psChar + 1;       }    }/* * Display the remainder if newlines whre encountered, otherwise display the * whole buffer*/if (*pszStartPos)    {    PaintOutputWindow (pszStartPos);    if (!strcmp(pszStartPos, NEWLINE))        ib_fprintf (fp, "%s", "\n");    else        ib_fprintf (fp, "%s", pszStartPos);    }#endif}#ifdef GUI_TOOLSint ISQL_sql_statement (    TEXT	*string,    IB_FILE	*ipf,    IB_FILE	*opf,    IB_FILE	*sf){/************************************** * *	I S Q L _ s q l _ s t a t e m e n t * ************************************** * * Functional description *	Process a SQL statement for Windows ISQL.   This sets up *	the input and output files, and executes the statement. * **************************************/int	ret;Out = opf;Ifp = ipf;Diag = Out;Help = Out;/* add command to command history file */ib_fprintf (sf, "%s%s", string, NEWLINE);ib_fflush (sf);ISQL_printf (Out, string);ISQL_printf (Out, NEWLINE);ret  = process_statement (string, sqldap, 0);if (ret == SKIP)    ret = 0;ISQL_printf (Out, NEWLINE);return (ret);}#endif/* #ifdef	DEV_BUILD Requested by Paul Beach. */static SSHORT add_row (    TEXT	*tabname){/************************************** * *	a d d _ r o w * ************************************** * * Functional description *	Allows interactive insert of row, prompting for every column * *	The technique is to describe a select query of select * from the table. *	Then generate an insert with ? in every position, using the same sqlda. *	It will allow edits of blobs, skip arrays and computed fields * *	Parameters: *	tabname -- Name of table to insert into * **************************************/SSHORT		n_cols, length, type, nullable, i, j, i_cols, done;SCHAR		string [BUFFER_LENGTH120], name [WORDLENGTH], buffer [BUFFER_LENGTH512], infobuf [BUFFER_LENGTH180];SCHAR		*insertstring = NULL, *stringvalue = NULL, cmd[5];SSHORT		*nullind = NULL, *nullp; /* Data types */SSHORT		*smallint, dscale;SSHORT		*colnumber;SLONG		*integer;SINT64		*pi64, n;float		*fvalue;double		*dvalue, numeric;SCHAR		bfile[120];struct tm	times;XSQLDA		*sqlda = NULL, *isqlda;XSQLVAR		*var, *ivar;SCHAR		*p;ISC_QUAD	*blobid;VARY		*vary;TEXT		msg [MSG_LENGTH];SLONG		res;if (!*tabname)    return (ERR);if (!Interactive)    return (ERR);/* Initialize the time structure */for (p = (SCHAR *) &times, i = sizeof (times); i; p++, i--)    *p = 0;/* There may have been a commit transaction before we got here */	if (!M__trans)    if (isc_start_transaction (isc_status, &M__trans, 1, &DB, 0, (SCHAR*) 0))	{        ISQL_errmsg (isc_status);	return FAIL;	};/* Start default transaction for prepare */if (!D__trans)    if (isc_start_transaction (isc_status, &D__trans, 1, &DB, 0, (SCHAR*) 0))	{        ISQL_errmsg (isc_status);	return FAIL;	};/* Query to obtain relation information */sprintf (string, "SELECT * FROM %s", tabname);sqlda = (XSQLDA*) ISQL_ALLOC ((SLONG) (XSQLDA_LENGTH (20)));sqlda->version = SQLDA_VERSION1;sqlda->sqln = 20;if (isc_dsql_prepare (isc_status, &D__trans, &Stmt, 0, string, 		      SQL_dialect, sqlda))    {    ISQL_errmsg (isc_status);    return (SKIP);    }n_cols = sqlda->sqld;/* Reallocate to the proper size if necessary */if (sqlda->sqld > sqlda->sqln)    {    ISQL_FREE (sqlda);    sqlda = (XSQLDA*) ISQL_ALLOC ((SLONG) (XSQLDA_LENGTH (n_cols)));    sqlda->sqld = sqlda->sqln = n_cols;    /*  We must re-describe the sqlda, no need to re-prepare */    if (isc_dsql_describe (isc_status, &Stmt, SQL_dialect, sqlda))	{        ISQL_errmsg (isc_status);	if (sqlda)	    ISQL_FREE (sqlda);        return (FAIL);	};    }/* Array for storing select/insert column mapping , colcheck sets it up*/colnumber = (SSHORT*) ISQL_ALLOC ((SLONG) (n_cols * sizeof (SSHORT)));col_check (tabname, colnumber);/* Create the new INSERT statement from the sqlda info */insertstring = (SCHAR*) ISQL_ALLOC ((SLONG) (40 + 36 * n_cols));/* There is a question marker for each column known updatable column */sprintf (insertstring, "INSERT INTO %s (", tabname);    for (i = 0, i_cols = 0, var = sqlda->sqlvar; i < n_cols; var++, i++)    {    /* Skip columns that are computed */    if (colnumber [i] != -1)	{	sprintf (insertstring + strlen (insertstring), "%s,", var->sqlname);	i_cols++;	}    }/* Set i_cols to the number of insert columns  */insertstring [strlen (insertstring) - 1] = ')';strcat(insertstring, " VALUES (");for (i = 0; i < n_cols; i++)    {    if (colnumber [i] != -1)	strcat (insertstring, " ?,");    }    /* Patch the last character in the string */insertstring [strlen (insertstring) - 1] = ')';	/* Allocate INSERT sqlda and  null indicators */isqlda = (XSQLDA*) ISQL_ALLOC ((SLONG) (XSQLDA_LENGTH (i_cols)));/* ISQL_ALLOC doesn't initialize the structure, so init everything * to avoid lots of problems. */for (p = (SCHAR *) isqlda, i = XSQLDA_LENGTH (i_cols); i; p++, i--)    *p = 0;isqlda->version = SQLDA_VERSION1;isqlda->sqln = isqlda->sqld = i_cols;nullind = (SSHORT*) ISQL_ALLOC ((SLONG) (i_cols * sizeof (SSHORT)));/***  For each column, get the type, and length then prompt for a value**  and ib_scanf the resulting string into a buffer of the right type.*/gds__msg_format (NULL_PTR, ISQL_MSG_FAC, ADD_PROMPT, sizeof (infobuf), infobuf, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR, NULL_PTR);STDERROUT (infobuf, 1);done = FALSE;while (!done)    {    nullp = nullind;    for (i = 0, var = sqlda->sqlvar; i < n_cols && !done; var++, i++)	{	if (colnumber [i] == -1)	    continue;	/* SQLDA for INSERT statement might have fewer columns */	j = colnumber[i];	ivar = &isqlda->sqlvar[j];	*ivar = *var;	length = var->sqllen;	*nullp = 0;	ivar->sqlind = nullp++;	ivar->sqldata = NULL;	strcpy (name, var->sqlname);	name[var->sqlname_length] = '\0';	type = var->sqltype & ~1;	nullable = var->sqltype & 1;	/* Prompt with the name and read the line */ 	if (type == SQL_BLOB)	    {	    ISQL_msg_get (BLOB_PROMPT, msg, name, NULL, NULL, NULL, NULL);	    ISQL_prompt (msg);   /* Blob: %s, type 'edit' or filename to load> */	    }	else if (type == SQL_TIMESTAMP || type == SQL_TYPE_DATE)	    {	    ISQL_msg_get (DATE_PROMPT, msg, name, NULL, NULL, NULL, NULL);	    ISQL_prompt (msg);   	/* Enter %s as M/D/Y> */	    }	else	    {	    ISQL_msg_get (NAME_PROMPT, msg, name, NULL, NULL, NULL, NULL);	    ISQL_prompt (msg);    	/* Enter %s> */	    }	/* On blank line or EOF, break the loop without doing an insert */	if (!ib_fgets (buffer,BUFFER_LENGTH512,ib_stdin) || !strlen (buffer))	    {	    done = TRUE;	    break;	    }	length = strlen (buffer);	STDERROUT ("", 1);	/* Convert first  4 chars to upper case for comparison */	strncpy (cmd, buffer, 4);	cmd[4] = '\0';	ISQL_make_upper (cmd);	/* If the user writes NULL, put a null in the column */	if (!strcmp (cmd, "NULL"))	    *ivar->sqlind = -1;	else	    switch (type)		{		case SQL_BLOB:		    blobid = (ISC_QUAD*) ISQL_ALLOC ((SLONG) sizeof (ISC_QUAD));		    if (!strcmp (cmd, "EDIT"))		        /* If edit, we edit a temp file */			{			tmpnam (bfile);			gds__edit (bfile, 0);		        res = BLOB_text_load (blobid, DB, M__trans, bfile);			unlink (bfile);			}		    else			/* Otherwise just load the named file */			/* We can't be sure if it's a TEXT or BINARY file			 * being loaded.  As we aren't sure, we'll			 * do binary operation - this is NEW data in			 * the database, not updating existing info			 */			{			strcpy (bfile, buffer);		        res = BLOB_load (blobid, DB, M__trans, bfile);			}		    if (!res)			{			STDERROUT ("Unable to load file", 1);			done = TRUE;			}					    ivar->sqldata = (SCHAR*) blobid;			    break;		case SQL_FLOAT:		    fvalue = (float*) ISQL_ALLOC (sizeof (float));		    if (sscanf (buffer, "%g", fvalue) != 1)			{			STDERROUT ("Input parsing problem", 1);			done = TRUE;			}		    ivar->sqldata = (SCHAR*) fvalue;		    break;		case SQL_DOUBLE:		    dvalue = (double*) ISQL_ALLOC (sizeof (double));		    if (ss

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -