标签: uuid

Android 检查 UUID 是否有效

有没有办法检查字符串是否是有效的 UUID?

在我的情况下,我有文件列表,其中一些文件名是由 生成的 UUID UUID.randomUUID().toString(),其余的只是普通.jpg文件。

我知道通过使用UUID.fromString(filename)和捕获IllegalArgumentException抛出,我将能够检查是否filename是格式正确的 UUID。但考虑到文件列表将包含大量文件,这似乎非常昂贵。有没有一种方法可以让我在不引发异常的情况下进行检查?

uuid android

1
推荐指数
1
解决办法
2638
查看次数

可以设置“UUID()”的长度吗?

我用mysql函数生成唯一和随机字符串UUID(),可以设置这个生成字符串的长度吗?我只需要8个字母。

这个插入是我用 php 插入函数做的...

先感谢您。

php mysql uuid

1
推荐指数
1
解决办法
1万
查看次数

BLE 从特征接收 GATT 通知

我希望在该特性发生更改时收到通知Micro:Bit

\n\n

我正在做的事情基本上如下:

\n\n

1)检查系统是否兼容BLE

\n\n

2) 启用蓝牙以防其被禁用

\n\n

3) 连接到唯一一个配对设备 (Micro:Bit)

\n\n

4) 当连接发生变化时激活此代码(\xc2\xbfConnected/Disconnected?)

\n\n

5) 当特性更新时激活此代码\xc2\xbf?

\n\n
public class MainActivity extends Activity {\n\nBluetoothAdapter bleAdapter;\n\n@Override\nprotected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.activity_main);\n\n    **(1)**\n\n    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {\n        Toast.makeText(this, "BLE Not Supported", Toast.LENGTH_SHORT).show();\n        finish();\n    }\n\n    **(2)**\n\n    bleAdapter = ((BluetoothManager) getSystemService(BLUETOOTH_SERVICE)).getAdapter();\n\n    if (bleAdapter == null || !bleAdapter.isEnabled()) {\n        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);\n        startActivityForResult(enableBtIntent, 1);\n    }\n\n    Set<BluetoothDevice> pairedDevices = bleAdapter.getBondedDevices();\n\n    for (BluetoothDevice device : pairedDevices) {\n\n        **(3)**\n\n        device.connectGatt(this, true, new BluetoothGattCallback() …
Run Code Online (Sandbox Code Playgroud)

uuid android characteristics bluetooth-lowenergy gatt

1
推荐指数
1
解决办法
5807
查看次数

在 H2 数据库引擎中指定 UUID 类型的主键列的默认值?

这个SQL:

\n\n
CREATE TABLE product_ ( \n    pkey_ UUID PRIMARY KEY\n) ; \n
Run Code Online (Sandbox Code Playgroud)\n\n

\xe2\x80\xa6成功创建表。

\n\n

但我希望新行默认为生成的 UUId,如本 AnswerRANDOM_UUID()所示。

\n\n
CREATE TABLE product_ ( \n    pkey_ UUID PRIMARY KEY DEFAULT RANDOM_UUID() \n) ; \n
Run Code Online (Sandbox Code Playgroud)\n\n

但这失败并出现错误:

\n\n
\n

org.h2.jdbc.JdbcSQLException: SQL 语句中的语法错误“CREATE TABLE PRODUCT_ (\n PKEY_ UUID PRIMARY KEY DEFAULT[*] RANDOM_UUID() \n ) ;”; 预期为“HASH、AUTO_INCRMENT、NOT、NULL、CHECK、REFERENCES、,、)”;SQL语句:

\n
\n\n

此错误的原因和解决方法是什么?

\n

uuid h2 primary-key create-table

1
推荐指数
1
解决办法
3567
查看次数

如何在 Swift 中创建 15 位长度的随机字符串?

In Javascript, Node.js I can generate with https://www.npmjs.com/package/uuid package a 15 digit length "random" string. Is it possible it with Swift?

Like this: 802128100247740

const uuidv4 = require("uuid/v4");
tempUserUuid = uuidv4();
Run Code Online (Sandbox Code Playgroud)

uuid swift

1
推荐指数
1
解决办法
821
查看次数

Laravel model::create() 不返回主键

我有以下身份验证表:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class CreateAuthTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('auth', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->string('email', 255)->index()->unique();
            $table->string('password', 96);
            $table->timestamps();
        });
        DB::statement('ALTER TABLE auth ALTER COLUMN id SET DEFAULT uuid_generate_v4();');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('auth');
    }
}

Run Code Online (Sandbox Code Playgroud)

这是模型:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticable;
use Illuminate\Support\Facades\Hash; …
Run Code Online (Sandbox Code Playgroud)

php postgresql uuid laravel

1
推荐指数
1
解决办法
1414
查看次数


使用UUID获取核心数据

如何使用 UUID 获取对象?我有一个对象 ( TimeCode),其属性属于xcdatamodel 文件中的id类型。UUID我想通过使用id标准中的此属性从 CoreData 获取此类型的对象NSPredicate,但出现编译错误,提示我必须将其用作ida CVarArg。但在运行时,当我实际调用该函数时,程序崩溃了,因为类型ObjectIdentifier无法转换为CVarArg.

这是完整的代码:

func fetchTimeCode(id: ObjectIdentifier) -> TimeCode? {
        var timeCodes = [TimeCode]()
        
        let request: NSFetchRequest<TimeCode> = TimeCode.fetchRequest()
        
        request.predicate = NSPredicate(format: "id ==  %@", id as! CVarArg)
        
        do {
            timeCodes = try self.moc.fetch(request)
        }
        catch let error as NSError {
            print("Error fetching for editing.")
            print(error)
        }
        
        print("fetch request id: \(id)")
        
        return timeCodes.first
    }
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激。我似乎到处寻找,却找不到任何答案。现在看来最好的解决方案是将 id 存储为字符串,但这似乎不是特别优雅。如果您无法轻松地使用 UUID …

uuid core-data swift swiftui

1
推荐指数
1
解决办法
2801
查看次数

spring / hibernate:为 Id 列自动生成 UUID

我正在尝试使用 Spring、hibernate/JPA 和 PostgreSQL 数据库来持久保存一个简单的类。

表的列ID是一个 UUID,我想在代码中生成它,而不是在数据库中。

这应该很简单,因为 hibernate 和 postgres 对 UUID 有很好的支持。

每次我创建一个新实例并使用 写入它时save(),都会收到以下错误:

o.h.j.JdbcSQLIntegrityConstraintViolationException: NULL not allowed for column "ID"; SQL statement: INSERT INTO DOODAHS (fieldA, fieldB) VALUES $1, $2) ...
Run Code Online (Sandbox Code Playgroud)

此错误表明它期望在插入行时自动填充 ID 列(使用某些默认值)。

该类看起来像这样:

@lombok.Data
@lombok.AllArgsConstructor
@org.springframework.data.relational.core.mapping.Table("doodahs")
public class Doodah {

    @org.springframework.data.annotation.Id
    @javax.persistence.GeneratedValue(generator = "UUID")
    @org.hibernate.annotations.GenericGenerator(name="UUID", strategy = "uuid2")
    @javax.persistence.Column(nullable = false, unique = true)
    private UUID id;

    //... other fields
Run Code Online (Sandbox Code Playgroud)

我尝试过的事情:

  1. @javax.persistence.Id使用(除了现有的 spring Id 之外)注释该字段
  2. 对该字段进行注释@org.hibernate.annotations.Type(type = …

java postgresql uuid hibernate spring-data-jpa

1
推荐指数
1
解决办法
1万
查看次数

Postgresql 15 - 数字文字错误后尾随垃圾

在 Postgresql 更新 v15 之后,我意识到即使我有一个接受 UUID 数据类型的列,每当我尝试将 UUID 数据插入表中时,它也会抛出类似的错误。

脚本:

INSERT INTO public.testing(uuid, rating) VALUES (${uuid}, ${rating});
Run Code Online (Sandbox Code Playgroud)

错误:

运行查询错误时出错:在“45c”或附近的数字文字后尾随垃圾

Postgresql 15 发行说明:

防止数字文字具有非数字尾随字符 (Peter Eisentraut)

这个问题有什么解决办法吗?或者有另一种数据类型允许将 UUID 存储到我的表中?

database postgresql uuid numeric query-error

1
推荐指数
1
解决办法
9010
查看次数