使用 R 编辑 .sql 文件

发布于 2025-01-16 19:49:22 字数 576 浏览 1 评论 0原文

我正在尝试获取一个 SQL 文件,使用 R 修改它,然后再次将其保存在另一个位置。作为此过程的一部分,我不想修改格式。

我尝试使用以下内容(我删除了转换步骤,因为它在这里无关紧要):

query <- readChar(location, file.info(location)$size)
writeLines(query, file.path(folder$new, script))

不幸的是,当我这样做时,查询似乎将所有新行加倍,当我打开新创建的 .sql 文件时,我得到警告消息“以下文件中的行结尾不一致。是否要标准化行结尾?”

我发现这个问题表明它是组合或 CR/LF 问题(为什么我在执行 sql 脚本时收到“不一致的结束行”警告窗口?),但我不知道如何修复/防止它们。

有人在这个领域取得过成功吗?也许有更好的读取 .sql 文件的方法?

I'm trying to take a SQL file, modify it using R and then save it again in another location. As part of this process, I don't want to modify the formatting.

I've tried using the following (I've stripped the transformation step because it's irrelevant here):

query <- readChar(location, file.info(location)$size)
writeLines(query, file.path(folder$new, script))

Unfortunately, when I do this, the query seems to double all new lines and when I open the newly created .sql file, I get the warning message "The line endings in the following file are not consistent. Do you want to normalize the line endings?"

I've found this question which suggests that it's a combination or CR/LF issues (why i am getting "Inconsistent ending lines" warning window while executing sql script?), but I don't know how to fix/prevent them.

Has anyone had any success in this area? Perhaps a better way of reading .sql files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文