首页 \ 问答 \ 如何使用web2py.DAL进行'between'查询?(how can I make 'between' query with web2py.DAL?)

如何使用web2py.DAL进行'between'查询?(how can I make 'between' query with web2py.DAL?)

我正在尝试创建一个接受两个datetime.date对象(start_date和end_date)的查询函数,并返回所有记录,其中包含start_date和end_date之间的相关字段。 但是,我在web2py手册中找不到类似的函数,所以我这样实现:

        for o in objects:
            # notice that create_time is a datetime field
            create_date = dt.datetime.strptime(o['create_time'], 
                                               "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")
        if query_dict['create_date_1'] <= create_date <= query_dict['create_date_2']:
            result.append(l)

对我的应用来说这样做太慢了,因为它们可能是很多对象。 那么,有没有更好的方法可以使用web2py.DAL实现这一点? 提前致谢 ;)


I'm trying to make a query function that accepts two datetime.date object(start_date and end_date), and return all records with a related field that's between start_date and end_date. However, I found nothing like a between function in the web2py manual, so I implement it this way:

        for o in objects:
            # notice that create_time is a datetime field
            create_date = dt.datetime.strptime(o['create_time'], 
                                               "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")
        if query_dict['create_date_1'] <= create_date <= query_dict['create_date_2']:
            result.append(l)

Doing this is too slow for my application because their can be many objects. So, is there a better way I can implement this using web2py.DAL? Thanks in advance ;)


原文:https://stackoverflow.com/questions/1907088
更新时间:2023-08-05 08:08

最满意答案

有办法搞定吗?

没有。

您需要修改您的库以接受某些内容作为输入,以便您可以在应用程序所需的位置和方式读取和写入数据。 理想情况下,您使用某种Java接口,允许应用程序具有一定的灵活性(例如,将数据存储在自己的加密容器中),并提供可能使用应用程序自己的Context File的库存实现。


there is way to get it?

No.

You will need to modify your library to accept something as input that will let you read and write your data where and how the app wants. Ideally, you use some sort of Java interface that allows the app some flexibility (e.g., stores your data in its own encrypted container), with you supplying a stock implementation that perhaps uses File from the app's own Context.

相关问答

更多
  • 如果您启用了USB调试,则可以尝试打开“adb shell”,并使用“su”命令获取root权限。 之后,您可以通过此shell窗口打开任何文件夹中的任何文件。 像在Linux中一样在文件夹之间移动,Google很容易如何做到这一点。 If you have USB debugging enabled, you can try to open "adb shell" and inside of it get root permissions using "su" command. After that yo ...
  • 资源是开发计算机上的文件。 它们不是设备上的文件。 它们只是APK文件中的条目。 您无法使用File访问它们。 Resources are files on your development machine. They are not files on the device. They are merely entries in your APK file. You cannot access them using File.
  • 对于文件: Context.getFileStreamPath() (或者整个目录的Context.getFilesDir() )。 对于数据库: Context.getDatabasePath() For files: Context.getFileStreamPath() (alternatively, Context.getFilesDir() for the whole directory). For databases: Context.getDatabasePath()
  • 确保你 : 根植了你的设备 有权在内部存储上书写 没有尝试在手机上启用USB存储器进行测试 在清单中添加了权限 I solved the problem by manually setting right owner, group and permissions on my application files folder (using chmod, cho ...
  • 这不是Android中的工作方式。 要调用另一个已安装的应用程序,您必须使用Intent 。 然后,Android将选择最适合您尝试的应用程序,并使用它们打开您需要的文件。 在您的示例中,代码将是这样的: Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(path, "application/pdf"); startActivity(Intent.createChooser(intent, "Open PDF")); ...
  • File mydir = context.getFilesDir(); File fileWithinMyDir = new File(mydir, "myfile/path/fileNmae"); if(fileWithinMyDir.exists()){ //exists }else{ //not exists } 更新: //File mydir = this.getFilesDir(); File mydir = this.getExter ...
  • 有办法搞定吗? 没有。 您需要修改您的库以接受某些内容作为输入,以便您可以在应用程序所需的位置和方式读取和写入数据。 理想情况下,您使用某种Java接口,允许应用程序具有一定的灵活性(例如,将数据存储在自己的加密容器中),并提供可能使用应用程序自己的Context File的库存实现。 there is way to get it? No. You will need to modify your library to accept something as input that will let you ...
  • 使用以下内容: File mydir = new File(path); File[] mydirlist = mydir.listFiles(); use something along the lines of the following: File mydir = new File(path); File[] mydirlist = mydir.listFiles();
  • 您可以在您的案例中使用应用程序数据文件夹,但使用将无法列出您将其放在appdata文件夹中的文件: https : //developers.google.com/drive/appdata 要将文件放在appdata文件夹中,只需将其父级设置为“appdata”: File body = new File(); body.setTitle(title); body.setDescription(description); body.setMimeType(mimeType); body.setParent ...
  • EDITED 如果要从当前文件夹中读取文件 System.IO.FileStream stream = System.Reflection.Assembly.GetExecutingAssembly().GetFile("filename"); 或者你想获得目录路径 string path = System.Reflection.Assembly.GetExecutingAssembly().Location; var directory = System.IO.Path.Get ...

相关文章

更多

最新问答

更多
  • 您如何使用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)