本文整理汇总了C#中Parse.NestedParse方法的典型用法代码示例。如果您正苦于以下问题:C# Parse.NestedParse方法的具体用法?C# Parse.NestedParse怎么用?C# Parse.NestedParse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parse
的用法示例。
在下文中一共展示了Parse.NestedParse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenStatTable
static void OpenStatTable(Parse parse, int db, int statCur, string where_, string whereType)
{
int[] roots = new int[] { 0, 0 };
byte[] createTbls = new byte[] { 0, 0 };
Context ctx = parse.Ctx;
Vdbe v = parse.GetVdbe();
if (v == null) return;
Debug.Assert(Btree.HoldsAllMutexes(ctx));
Debug.Assert(v.Ctx == ctx);
Context.DB dbObj = ctx.DBs[db];
for (int i = 0; i < _tables.Length; i++)
{
string tableName = _tables[i].Name;
Table stat;
if ((stat = Parse.FindTable(ctx, tableName, dbObj.Name)) == null)
{
// The sqlite_stat[12] table does not exist. Create it. Note that a side-effect of the CREATE TABLE statement is to leave the rootpage
// of the new table in register pParse.regRoot. This is important because the OpenWrite opcode below will be needing it.
parse.NestedParse("CREATE TABLE %Q.%s(%s)", dbObj.Name, tableName, _tables[i].Cols);
roots[i] = parse.RegRoot;
createTbls[i] = Vdbe::OPFLAG_P2ISREG;
}
else
{
// The table already exists. If zWhere is not NULL, delete all entries associated with the table zWhere. If zWhere is NULL, delete the
// entire contents of the table.
roots[i] = stat.Id;
sqlite3TableLock(parse, db, roots[i], 1, tableName);
if (where_ == null)
parse.NestedParse("DELETE FROM %Q.%s WHERE %s=%Q", dbObj.Name, tableName, whereType, where_);
else
v.AddOp2(OP.Clear, roots[i], db); // The sqlite_stat[12] table already exists. Delete all rows.
}
}
// Open the sqlite_stat[12] tables for writing.
for (int i = 0; i < _tables.Length; i++)
{
v.AddOp3(OP.OpenWrite, statCur + i, roots[i], db);
v.ChangeP4(-1, 3, Vdbe.P4T.INT32);
v.ChangeP5(createTbls[i]);
}
}
示例2: FinishAddColumn
public static void FinishAddColumn(Parse parse, Token colDef)
{
Context ctx = parse.Ctx; // The database connection
if (parse.Errs != 0 || ctx.MallocFailed) return;
Table newTable = parse.NewTable; // Copy of pParse.pNewTable
Debug.Assert(newTable != null);
Debug.Assert(Btree.HoldsAllMutexes(ctx));
int db = Prepare.SchemaToIndex(ctx, newTable.Schema); // Database number
string dbName = ctx.DBs[db].Name;// Database name
string tableName = newTable.Name.Substring(16); // Table name: Skip the "sqlite_altertab_" prefix on the name
Column col = newTable.Cols[newTable.Cols.length - 1]; // The new column
Expr dflt = col.Dflt; // Default value for the new column
Table table = Parse.FindTable(ctx, tableName, dbName); // Table being altered
Debug.Assert(table != null);
#if !OMIT_AUTHORIZATION
// Invoke the authorization callback.
if (Auth.Check(parse, AUTH.ALTER_TABLE, dbName, table.Name, null))
return;
#endif
// If the default value for the new column was specified with a literal NULL, then set pDflt to 0. This simplifies checking
// for an SQL NULL default below.
if (dflt != null && dflt.OP == TK.NULL)
dflt = null;
// Check that the new column is not specified as PRIMARY KEY or UNIQUE. If there is a NOT NULL constraint, then the default value for the
// column must not be NULL.
if ((col.ColFlags & COLFLAG.PRIMKEY) != 0)
{
parse.ErrorMsg("Cannot add a PRIMARY KEY column");
return;
}
if (newTable.Index != null)
{
parse.ErrorMsg("Cannot add a UNIQUE column");
return;
}
if ((ctx.Flags & Context.FLAG.ForeignKeys) != 0 && newTable.FKeys != null && dflt != null)
{
parse.ErrorMsg("Cannot add a REFERENCES column with non-NULL default value");
return;
}
if (col.NotNull != 0 && dflt == null)
{
parse.ErrorMsg("Cannot add a NOT NULL column with default value NULL");
return;
}
// Ensure the default expression is something that sqlite3ValueFromExpr() can handle (i.e. not CURRENT_TIME etc.)
if (dflt != null)
{
Mem val = null;
if (Mem_FromExpr(ctx, dflt, TEXTENCODE.UTF8, AFF.NONE, ref val) != 0)
{
ctx.MallocFailed = true;
return;
}
if (val == null)
{
parse.ErrorMsg("Cannot add a column with non-constant default");
return;
}
Mem_Free(ref val);
}
// Modify the CREATE TABLE statement.
string colDefAsString = colDef.data.Substring(0, (int)colDef.length).Replace(";", " ").Trim(); // Null-terminated column definition
if (colDefAsString != null)
{
Context.FLAG savedDbFlags = ctx.Flags;
ctx.Flags |= Context.FLAG.PreferBuiltin;
parse.NestedParse(
"UPDATE \"%w\".%s SET " +
"sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) " +
"WHERE type = 'table' AND name = %Q",
dbName, E.SCHEMA_TABLE(db), newTable.AddColOffset, colDefAsString, newTable.AddColOffset + 1,
tableName);
C._tagfree(ctx, ref colDefAsString);
ctx.Flags = savedDbFlags;
}
// If the default value of the new column is NULL, then set the file format to 2. If the default value of the new column is not NULL,
// the file format becomes 3.
MinimumFileFormat(parse, db, (dflt != null ? 3 : 2));
// Reload the schema of the modified table.
ReloadTableSchema(parse, table, table.Name);
}
示例3: RenameTable
public static void RenameTable(Parse parse, SrcList src, Token name)
{
Context ctx = parse.Ctx; // Database connection
Context.FLAG savedDbFlags = ctx.Flags; // Saved value of db->flags
//if (C._NEVER(ctx.MallocFailed)) goto exit_rename_table;
Debug.Assert(src.Srcs == 1);
Debug.Assert(Btree.HoldsAllMutexes(ctx));
Table table = parse.LocateTableItem(false, src.Ids[0]); // Table being renamed
if (table == null) goto exit_rename_table;
int db = Prepare.SchemaToIndex(ctx, table.Schema); // Database that contains the table
string dbName = ctx.DBs[db].Name; // Name of database iDb
ctx.Flags |= Context.FLAG.PreferBuiltin;
// Get a NULL terminated version of the new table name.
string nameAsString = Parse.NameFromToken(ctx, name); // NULL-terminated version of pName
if (nameAsString == null) goto exit_rename_table;
// Check that a table or index named 'zName' does not already exist in database iDb. If so, this is an error.
if (Parse.FindTable(ctx, nameAsString, dbName) != null || Parse.FindIndex(ctx, nameAsString, dbName) != null)
{
parse.ErrorMsg("there is already another table or index with this name: %s", nameAsString);
goto exit_rename_table;
}
// Make sure it is not a system table being altered, or a reserved name that the table is being renamed to.
if (IsSystemTable(parse, table.Name) || parse->CheckObjectName(nameAsString) != RC.OK)
goto exit_rename_table;
#if !OMIT_VIEW
if (table.Select != null)
{
parse.ErrorMsg("view %s may not be altered", table.Name);
goto exit_rename_table;
}
#endif
#if !OMIT_AUTHORIZATION
// Invoke the authorization callback.
if (Auth.Check(parse, AUTH.ALTER_TABLE, dbName, table.Name, null))
goto exit_rename_table;
#endif
VTable vtable = null; // Non-zero if this is a v-tab with an xRename()
#if !OMIT_VIRTUALTABLE
if (parse->ViewGetColumnNames(table) != 0)
goto exit_rename_table;
if (E.IsVirtual(table))
{
vtable = VTable.GetVTable(ctx, table);
if (vtable.IVTable.IModule.Rename == null)
vtable = null;
}
#endif
// Begin a transaction and code the VerifyCookie for database iDb. Then modify the schema cookie (since the ALTER TABLE modifies the
// schema). Open a statement transaction if the table is a virtual table.
Vdbe v = parse.GetVdbe();
if (v == null) goto exit_rename_table;
parse.BeginWriteOperation((vtable != null ? 1 : 0), db);
parse.ChangeCookie(db);
// If this is a virtual table, invoke the xRename() function if one is defined. The xRename() callback will modify the names
// of any resources used by the v-table implementation (including other SQLite tables) that are identified by the name of the virtual table.
#if !OMIT_VIRTUALTABLE
if (vtable != null)
{
int i = ++parse.Mems;
v.AddOp4(OP.String8, 0, i, 0, nameAsString, 0);
v.AddOp4(OP.VRename, i, 0, 0, vtable, Vdbe.P4T.VTAB);
parse.MayAbort();
}
#endif
// figure out how many UTF-8 characters are in zName
string tableName = table.Name; // Original name of the table
int tableNameLength = C._utf8charlength(tableName, -1); // Number of UTF-8 characters in zTabName
#if !OMIT_TRIGGER
string where_ = string.Empty; // Where clause to locate temp triggers
#endif
#if !OMIT_FOREIGN_KEY && !OMIT_TRIGGER
if ((ctx.Flags & Context.FLAG.ForeignKeys) != 0)
{
// If foreign-key support is enabled, rewrite the CREATE TABLE statements corresponding to all child tables of foreign key constraints
// for which the renamed table is the parent table.
if ((where_ = WhereForeignKeys(parse, table)) != null)
{
parse.NestedParse(
"UPDATE \"%w\".%s SET " +
"sql = sqlite_rename_parent(sql, %Q, %Q) " +
"WHERE %s;", dbName, E.SCHEMA_TABLE(db), tableName, nameAsString, where_);
C._tagfree(ctx, ref where_);
}
}
#endif
// Modify the sqlite_master table to use the new table name.
//.........这里部分代码省略.........