首页 \ 问答 \ 如何在SQLite中重命名索引?(How to rename an index in SQLite?)

如何在SQLite中重命名索引?(How to rename an index in SQLite?)

在MySQL等其他数据库中,我可以这样做:

ALTER TABLE demo RENAME INDEX old_index TO new_index

什么是SQLite最好的解决方法?

更新

SQLite似乎不支持这种语法。 在哪种情况下我可以使用的工作。 例如:

DROP INDEX old_index;
CREATE INDEX new_index ON demo(col1, col2);

上面的问题是我需要手动找出索引的列。 我想要一些可以自动完成的事情,如:

set columns = select columns indexed by old_index;
DROP INDEX old_index;
CREATE INDEX new_index ON demo(columns);

In other databases such as MySQL I could just do this:

ALTER TABLE demo RENAME INDEX old_index TO new_index

What's the best workaround for SQLite?

Update

SQLite does not seem to support this syntax. In which case is there a work around I can use. For example:

DROP INDEX old_index;
CREATE INDEX new_index ON demo(col1, col2);

The issue with the above is that I need to manually find out which columns were indexed. I want something that can be done automatically like:

set columns = select columns indexed by old_index;
DROP INDEX old_index;
CREATE INDEX new_index ON demo(columns);

原文:
更新时间:2022-06-29 10:06

最满意答案

菜单不完整,你只是没有正确检查代码。

以下代码将加载菜单的数组。 该数组包含构建菜单所需的全部信息。 然后,您可以递归地循环访问数组,以使用您需要的HTML结构来构建菜单。 如果您将此菜单添加到现有菜单中,这很有用,因为它允许您匹配现有菜单使用的HTML结构。

// This uses the object manager
// A better way would be to inject the MenuFactory in your constructor
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$menu = $objectManager->create('FishPig\WordPress\Model\MenuFactory')->create();

$menuId = 3;

if ($menu->load($menuId)->getId()) {
    echo sprintf('<pre>%s</pre>', print_r($menu->getMenuTreeArray(), true));
}
else {
    echo 'No menu exists in WordPress with an ID of ' . (int)$menuId;
}

如果您不关心使用哪种HTML结构,则可以使用以下块:

\FishPig\WordPress\Block\Sidebar\Widget\NavMenu

如果您查看该块的代码,您会看到它检查数据项“nav_menu”以获取菜单ID。 你可以通过XML来设置它(如果你通过XML创建块)或者使用PHP创建整个事物:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$menuBlock = $objectManager->create('FishPig\WordPress\Block\Sidebar\Widget\NavMenuFactory')->create();

$menuId = 3;

echo $menuBlock->setNavMenu($menuId)->toHtml();

这个解决方案不如原来的解决方案好,因为它迫使你使用特定的HTML结构。 使用第一种解决方案会更好,因为这可以让您使用任何您需要的HTML结构。 你的主题可能已经有一个CSS规则和JS的菜单,所以你可以使用这个方法在正确的HTML结构中建立菜单。


Menu's are not incomplete, you just haven't checked the code properly.

The following code will load an array of the menu. This array contains all of the information you need to build the menu. You can then recursively loop through the array to build the menu using the HTML structure that you require. This is useful if you are adding this menu to an existing menu as it allows you to match the HTML structure used by your existing menu.

// This uses the object manager
// A better way would be to inject the MenuFactory in your constructor
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$menu = $objectManager->create('FishPig\WordPress\Model\MenuFactory')->create();

$menuId = 3;

if ($menu->load($menuId)->getId()) {
    echo sprintf('<pre>%s</pre>', print_r($menu->getMenuTreeArray(), true));
}
else {
    echo 'No menu exists in WordPress with an ID of ' . (int)$menuId;
}

If you don't care what HTML structure is used, you can use the following block:

\FishPig\WordPress\Block\Sidebar\Widget\NavMenu

If you look through the code of this block, you will see it checks the data item 'nav_menu' for the menu ID. You can set this via XML (if you created the block via XML) or create the whole thing using PHP:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$menuBlock = $objectManager->create('FishPig\WordPress\Block\Sidebar\Widget\NavMenuFactory')->create();

$menuId = 3;

echo $menuBlock->setNavMenu($menuId)->toHtml();

This solution isn't as good as the original solution though as it forces you to use a specific HTML structure. You would be much better using the first solution, as this will allow you to use any HTML structure that you require. Your theme probably already has a menu with CSS rules and JS in place so you could use this method to build the menu in the correct HTML structure.

相关问答

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)