6 Replies - 603 Views - Last Post: 02 September 2013 - 01:52 PM Rate Topic: -----

#1 the5thelement  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 59
  • Joined: 30-July 12

Generating GUID

Posted 02 September 2013 - 12:48 PM

Hello! I am working on a project that uses a MySQL database.
Within the MySQL database is a GUID column that holds an
integer 10 characters long.

I am wondering if it is possible to generate a GUID that is
from 1 to 10 characters long and is integer only.

The current GUID generation returns a value like this one
d6cb2c96-c341-43ee-aba9-2bcb1a17c5f6.

This is my current code for generating a GUID.
Imports System.IO
Public Class Form1
    Dim GUIDlist As New List(Of String)
    Dim GUIDstring As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GenerateGUID()
    End Sub
    Public Sub GenerateGUID()
        Dim GUID As New System.Guid
        GUIDstring = GUID.NewGuid.ToString
        CheckGUIDList()
    End Sub
    Public Sub CheckGUIDList()
        If GUIDlist.Contains(GUIDstring) Then
            GenerateGUID()
        Else
            If GUIDlist.Count = 25 Then
                Dim GUIDstream As New StreamWriter(My.Computer.FileSystem.CurrentDirectory & "\GUID.txt")
                For Each I In GUIDlist
                    GUIDstream.WriteLine(I)
                Next
                GUIDstream.Close()
                Me.Close()
            Else
                GUIDlist.Add(GUIDstring)
                GenerateGUID()
            End If
        End If
    End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: Generating GUID

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9223
  • View blog
  • Posts: 34,630
  • Joined: 12-June 08

Re: Generating GUID

Posted 02 September 2013 - 12:56 PM

Quote

Hello! I am working on a project that uses a MySQL database.
Within the MySQL database is a GUID column that holds an
integer 10 characters long.

Typically I would store a GUID in a 38 varchar column. I typically let the database handle generating the GUID (if that is a key column) by having it default the value to the function: UUID() .

Quote

I am wondering if it is possible to generate a GUID that is
from 1 to 10 characters long and is integer only.


That wouldn't be a GUID then, would it? A GUID is a specific type of complex data type.. if you go off and make something else - well.. then that's on your head to check for uniqueness, collision, etc.
Was This Post Helpful? 0
  • +
  • -

#3 the5thelement  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 59
  • Joined: 30-July 12

Re: Generating GUID

Posted 02 September 2013 - 01:07 PM

The database is for an online game. I cannot change how the
GUID system works. I guess I could make the generation pick
a number between 1 and 9999999999 and check if it exists or
not. But it will take a long time for it to work if the table
has thousands of entries.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3491
  • View blog
  • Posts: 11,910
  • Joined: 12-December 12

Re: Generating GUID

Posted 02 September 2013 - 01:22 PM

I am not clear why you would think it would take a long time? Checking if a value exists in a table (using a WHERE clause) and then generating a new number if necessary, won't take very long. Perhaps I've misunderstood.
Was This Post Helpful? 0
  • +
  • -

#5 the5thelement  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 59
  • Joined: 30-July 12

Re: Generating GUID

Posted 02 September 2013 - 01:32 PM

I guess I just thought it would take awhile seeing as it would have to check thousands of rows.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3491
  • View blog
  • Posts: 11,910
  • Joined: 12-December 12

Re: Generating GUID

Posted 02 September 2013 - 01:34 PM

View Postthe5thelement, on 02 September 2013 - 08:32 PM, said:

I guess I just thought it would take awhile seeing as it would have to check thousands of rows.

That's what databases are for :sorcerer: - fast retrieval from structured data - put an index on the column though.

This post has been edited by andrewsw: 02 September 2013 - 01:37 PM

Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9223
  • View blog
  • Posts: 34,630
  • Joined: 12-June 08

Re: Generating GUID

Posted 02 September 2013 - 01:52 PM

View Postthe5thelement, on 02 September 2013 - 03:07 PM, said:

The database is for an online game. I cannot change how the
GUID system works. I guess I could make the generation pick
a number between 1 and 9999999999 and check if it exists or
not. But it will take a long time for it to work if the table
has thousands of entries.

.. did you not make this game or what?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1