sqliterk_column.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Tencent is pleased to support the open source community by making
  3. * WCDB available.
  4. *
  5. * Copyright (C) 2017 THL A29 Limited, a Tencent company.
  6. * All rights reserved.
  7. *
  8. * Licensed under the BSD 3-Clause License (the "License"); you may not use
  9. * this file except in compliance with the License. You may obtain a copy of
  10. * the License at
  11. *
  12. * https://opensource.org/licenses/BSD-3-Clause
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. #include "sqliterk_column.h"
  21. #include "sqliterk_os.h"
  22. struct sqliterk_column {
  23. int64_t rowid;
  24. sqliterk_values *values;
  25. sqliterk_values *overflowPages;
  26. };
  27. int sqliterkColumnAlloc(sqliterk_column **column)
  28. {
  29. if (!column) {
  30. return SQLITERK_MISUSE;
  31. }
  32. int rc = SQLITERK_OK;
  33. sqliterk_column *theColumn = sqliterkOSMalloc(sizeof(sqliterk_column));
  34. if (!theColumn) {
  35. rc = SQLITERK_NOMEM;
  36. goto sqliterkColumnAlloc_Failed;
  37. }
  38. rc = sqliterkValuesAlloc(&theColumn->values);
  39. if (rc != SQLITERK_OK) {
  40. goto sqliterkColumnAlloc_Failed;
  41. }
  42. rc = sqliterkValuesAlloc(&theColumn->overflowPages);
  43. if (rc != SQLITERK_OK) {
  44. goto sqliterkColumnAlloc_Failed;
  45. }
  46. *column = theColumn;
  47. return SQLITERK_OK;
  48. sqliterkColumnAlloc_Failed:
  49. if (theColumn) {
  50. sqliterkColumnFree(theColumn);
  51. }
  52. *column = NULL;
  53. return rc;
  54. }
  55. int sqliterkColumnFree(sqliterk_column *column)
  56. {
  57. if (!column) {
  58. return SQLITERK_MISUSE;
  59. }
  60. if (column->overflowPages) {
  61. sqliterkValuesFree(column->overflowPages);
  62. }
  63. if (column->values) {
  64. sqliterkValuesFree(column->values);
  65. }
  66. sqliterkOSFree(column);
  67. return SQLITERK_OK;
  68. }
  69. sqliterk_values *sqliterkColumnGetValues(sqliterk_column *column)
  70. {
  71. if (!column) {
  72. return NULL;
  73. }
  74. return column->values;
  75. }
  76. void sqliterkColumnSetRowId(sqliterk_column *column, int64_t rowid)
  77. {
  78. if (column) {
  79. column->rowid = rowid;
  80. }
  81. }
  82. int64_t sqliterkColumnGetRowId(sqliterk_column *column)
  83. {
  84. if (!column) {
  85. return 0;
  86. }
  87. return column->rowid;
  88. }
  89. sqliterk_values *sqliterkColumnGetOverflowPages(sqliterk_column *column)
  90. {
  91. if (!column) {
  92. return NULL;
  93. }
  94. return column->overflowPages;
  95. }
  96. int sqliterkColumnClear(sqliterk_column *column)
  97. {
  98. if (!column) {
  99. return SQLITERK_MISUSE;
  100. }
  101. column->rowid = 0;
  102. sqliterkValuesClear(column->overflowPages);
  103. sqliterkValuesClear(column->values);
  104. return SQLITERK_OK;
  105. }